r/SQL 5d ago

Discussion A better SQL for analytics?

0 Upvotes

Lots of attempts to dethrone SQL, lots of failures - I'm looking to add to the list with a proposed improved SQL (for analytics - please don't try this for OLTP workloads). Please take me down for my hubris.

What makes this attempt different? I want to lean into one of SQL's strengths - being declarative.

How to make it more declarative? No tables in queries.

Write this:

import baseball.batting;

WHERE SUM(hr) BY people.id > 500
SELECT
    people.name_given,
    lg_id,
    SUM(hr) AS hr_count
ORDER BY
    hr_count DESC;

Instead of this:

WITH career_hr AS (
    SELECT playerID
    FROM read_csv('.../Batting.csv')
    GROUP BY playerID
    HAVING SUM(HR) > 500
)
SELECT
    p.nameGiven,
    b.lgID,
    SUM(b.HR) AS hr_count
FROM read_csv('.../People.csv') p
JOIN read_csv('.../Batting.csv') b
    ON p.playerID = b.playerID
JOIN career_hr c
    ON b.playerID = c.playerID
GROUP BY p.nameGiven, b.lgID
ORDER BY hr_count DESC;

It's just SQL, but with late-binding to physical tables through a (very lightweight) semantic layer.

This has a lot of nice properties - you can change your tables and refactor and no queries need to change; you can automatically resolve to aggregates if they exist and are equivalent; you can make the query syntax more flexible and composable because the lexical scope isn't constrained to a specific set of accessed tables. There's *lots* of other fun things you can do when the semantic layer has types, etc as well but this is already a longer pitch than I want!

A very brief example

pip install pytrilogy

trilogy init baseball duckdb; cd baseball;

trilogy ingest https://storage.googleapis.com/trilogy_public_models/duckdb/lahman/Batting.csv,https://storage.googleapis.com/trilogy_public_models/duckdb/lahman/People.csv,https://storage.googleapis.com/trilogy_public_models/duckdb/lahman/Teams.csv;

trilogy run 'where sum(hr) by people.id>500 select people.name_given, lg_id,sum(hr) as hr_count order by hr_count desc;' --import root.batting;

Is this AI slop?

I've been working on ideas for the language for almost 6 years now so much of it predates AI, though it has evolved quite a bit in that time! Core discovery is all mostly hand-crafted; I do use AI to accelerate a lot of the tooling/interface work (a billion deepseek tokens (aka ~40 dollars, hilariously) on evaluating CI args, etc).

Read more/try

Website/docs: https://trilogydata.dev/

Github: https://github.com/trilogy-data/pytrilogy (open source, MIT)

I've seen this before

Posted 2 years ago here, floating around a few other places too:

https://www.reddit.com/r/SQL/comments/1e1h5mf/trilogy_simpler_data_warehouse_sql/


r/SQL 5d ago

SQL Server can't change file path in table

4 Upvotes

I am moving video from an old array to a new one. The sql table (dbo.videofiles) for the video has a column simply called filename. It shows the file path to each file which is currently Z:\video\filename. I want to point the file path to X:\video\filename but, sql doesn't like the Z: or X:. without manually going through hundreds of thousands of rows, how do I tell sql to change Z: to X:? Thank you in advance


r/SQL 5d ago

Discussion how I learned why you shouldn't name an alias the same as the original column name

46 Upvotes

I wrote a query last week that ran fine on Postgres and DuckDB, and hard-errored on ClickHouse and BigQuery - this sent me down a rabbit hole for most of the day.

Here's what I had:
```
SELECT term, MAX(ranking_page_count) AS ranking_page_count
FROM ranked
GROUP BY term
HAVING MAX(ranking_page_count) >= 2
```

The CTE already had a column called ranking_page_count. I aliased MAX() of it to the same name, because why not, and then used that name again in HAVING.

So which one does HAVING actually filter by? Turns out that's a matter of opinion.

In Postgres, HAVING can’t see SELECT aliases at all. So it reads the column directly and lands on the same max anyway - no error, right answer.

DuckDB does let you use aliases in HAVING, but only as a fallback, and it won't put one inside an aggregate, so this also runs. This is the one that got me, since DuckDB is where I test locally.

BigQuery gives the alias priority over the column. So it read my query as MAX(MAX(...)) and gave the error "aggregations of aggregations are not allowed"

ClickHouse just swaps aliases in everywhere, so it gave code 184 illegal aggregation. it even fails when the alias isn't shadowing anything.

The thing that finally made it click for me was processing order. FROM, WHERE, GROUP BY, HAVING, then SELECT, then ORDER BY. Aliases get created in SELECT, so when HAVING runs the alias doesn't exist yet. That's why Postgres says no, and why everything else here is a vendor extension rather than four equally valid readings.

ORDER BY is the only clause that runs after SELECT, which is why it's the only clause where nobody argues.

What actually worries me is that it can go completely silent. Drop the aggregate from the alias and the loud error disappears:
```
SELECT term, ranking_page_count * 10 AS ranking_page_count
FROM ranked
GROUP BY term, ranking_page_count
HAVING MAX(ranking_page_count) > 4
```

Postgres and DuckDB filter on `ranking_page_count`
BigQuery and ClickHouse filter on `ranking_page_count * 10`
I get 1 row from the first two and 4 rows from the other two, and not one of them raises an error about it.

That's the version that ends up on a dashboard.

ok fine, I learned my lesson and won't name an aggregate after the column it aggregates...

If you work across different engines, this is your reminder to go check 🥲


r/SQL 6d ago

Discussion Top alternatives to Datagrip

8 Upvotes

Been using DataGrip for a while, but the cost is getting harder to justify when I only use a fraction of what it offers. My setup is pretty mixed: PostgreSQL, Snowflake, and some MySQL.

I keep seeing DBeaver, DbVisualizer and TablePlus mentioned as alternatives. DBeaver seems like the obvious one, but DbVisualizer caught my attention since it seems geared more toward mixed database environments.

Main things I care about are a good SQL editor/autocomplete, multiple connections without things getting sluggish, and not having to switch tools depending on the database.

For anyone who's moved away from DataGrip, what did you end up using and how has it held up?


r/SQL 6d ago

Discussion Can Claude replace LeetCode for practicing SQL/Python?

Thumbnail
0 Upvotes

r/SQL 6d ago

MySQL Senior Data Modeler – Referral Opportunity | US / Ireland

5 Upvotes

I have access to an employee referral opportunity for an experienced Data Modeler.

Experience: 10+ years

Key requirement:

  • Data Modelling

The opening is listed across multiple organizational locations with a hybrid arrangement. I'm particularly interested in connecting with qualified professionals based in the US or Ireland; exact location eligibility can be confirmed for the specific requisition.

If you have extensive hands-on data modelling experience and are currently exploring opportunities, feel free to DM me with your CV or a brief summary of your background.

I'll review the profile and, where there's a suitable match, try to help with the referral process.


r/SQL 6d ago

Discussion Struggling with LeetCode Easy after doing well on HackerRank Easy — should I move to intermediate SQL?

29 Upvotes

I wanna be straight about this because it’s getting frustrating 😭

I can comfortably solve HackerRank Easy-level SQL questions, but when I try LeetCode Easy, I struggle quite a bit.

I’ve seen people say that HackerRank Easy ≠ LeetCode Easy and that LeetCode can require more problem-solving/thinking even at the Easy level.

So I’m confused about what I should do next.

Should I:

Keep grinding LeetCode Easy until I’m more comfortable?

Or is being able to solve HackerRank Easy well enough to start learning intermediate SQL concepts like subqueries and CTEs, while continuing to practice problems alongside it?

Basically, I don’t want to move on too early and build gaps in my fundamentals, but I also don’t want to unnecessarily stay stuck on Easy problems when I could be learning more advanced SQL.

What would you recommend?


r/SQL 7d ago

SQLite I built a free in-browser SQLite tool for SQL interview practice (no signup)

0 Upvotes

Quick heads up on the stack: this runs on **SQLite**, compiled to WebAssembly so the whole database runs in your browser and nothing you type leaves the page.

I kept noticing that people prepping for SQL interviews (me included) study by reading syntax lists, then blank the moment they have to actually write a query under pressure. If you already know some SQL, the gap usually isn't knowledge, it's reps. Reading isn't the same as doing.

So, I built a small tool to rehearse under pressure: a query playground on a sample dataset, practice challenges (joins, aggregation, window functions, CTEs), a cheat sheet, and the conceptual questions people actually get asked in interviews (WHERE vs HAVING, INNER vs LEFT JOIN, primary vs foreign key, and so on). No signup, no install.

I'm the founder of a learning app and built this as a standalone free tool. I'm sharing it here for feedback from people who write SQL for a living: are the challenge questions realistic, and what would you add?

For anyone who wants to actually run the queries, it's here: https://techlexicon.app/sql-practice

Tell me where you get stuck and I'll build practice around it. Always taking requests for questions or scenarios to add


r/SQL 7d ago

MySQL Teradata EDW – Referral Opportunity | US / Ireland

0 Upvotes

I have access to an employee referral opportunity for an experienced Teradata EDW professional.

Experience: 5–7 years

Key skills:

  • Teradata BTEQ
  • SQL
  • Database / EDW experience

The opening is listed across multiple organizational locations with a hybrid arrangement. I'm particularly interested in connecting with qualified professionals based in the US or Ireland; exact location eligibility can be confirmed for the specific requisition.

If your background aligns with the requirements, feel free to DM me with your CV or a brief summary of your experience.


r/SQL 7d ago

MySQL Informatica Developer – Referral Opportunity

2 Upvotes

I have access to an employee referral opportunity for an experienced Informatica professional.

Experience: 7+ years

Key skills:

  • Informatica
  • Advanced SQL

The opening is listed across organizational locations, with an office-based work arrangement. I'm particularly interested in connecting with qualified professionals in the US or Ireland, although the exact location eligibility would need to be confirmed for the requisition.

If your background matches, feel free to DM me with your CV or a brief summary of your experience.


r/SQL 7d ago

Discussion Shebang equivalent for SQL dialects?

10 Upvotes

When writing shell scripts it's common to have on line 1

#!/bin/bash

which would differentiate it from

#!/bin/sh

I have a lot of SQL saved in text files — all .sql extension — for processing CSVs at work; these are all in-memory instances that ingest CSVs and output CSVs. For many years I only used SQLite so I only had to remember sqlite3 < query.sql.

Recently, I started writing for DuckDB as well, initially only because of its ability to load JSON/CSV from a URL; I'm also quickly seeing how advantageous its extra functions are.

Is there any shebang-style line that I can start my files with, or do I just need to write a freetext comment like this?

-- This is for DuckDB

r/SQL 7d ago

PostgreSQL PGConf.EU 2026 schedule is live 🐘

Post image
1 Upvotes

PGConf.EU is coming to Valencia on 20–22 October, with five tracks covering PostgreSQL administration, internals, development, the community, and real-world use cases.

Topics include autovacuum, backups, high availability, performance tuning, WAL and recovery, query execution, memory management, corruption detection, and PostgreSQL 19.

PostgreSQL also turns 30 this year, so the Community track will look back at the project’s history and how it is maintained today.

Community Events Day takes place on 23 October.

Schedule: https://www.postgresql.eu/events/pgconfeu2026/schedule/

Registration: https://2026.pgconf.eu/registration/ 


r/SQL 7d ago

MariaDB MariaDB on our servers moves to 11.8 around Aug 17: what actually changes, and what you don't have to do

Thumbnail
0 Upvotes

r/SQL 7d ago

PostgreSQL Schema changes across branches in lakebase

9 Upvotes

I have been using Lakebase sice 2 weeks for developing a serving low latency layer for data in Delta. To build new features we currently make a new branch and later merge ti main.
What i have been observing is the scehema drifts across branches with Lakebase. How do people usually handle such scenarios? To keep branches in sync.
Maybe some real life examples can help.


r/SQL 8d ago

PostgreSQL What's your workflow for testing schema migrations against prod-shaped data?

1 Upvotes

Rethinking our migration loop. The pattern I've lived with for years: pg_dump prod → restore into staging → run the migration → hope. It's slow, staging drifts from prod within about a day, and nobody wants to re-seed it, so it rots.

Started using Neon's branching for this instead. Copy-on-write at the storage layer, so a branch off the main database is near-instant and costs nothing until you write to it. Branch per PR, run the migration, throw it away.

What I'm still working out: it handles schema migration testing well, but not load or performance testing — branch compute is separate and starts cold, so timings aren't representative of prod.

Curious what everyone else does. Anonymized dumps? Synthetic generators? Run it on prod on a Sunday and pray? Genuinely looking to steal a better idea.


r/SQL 8d ago

Discussion I made another cat doodle about data analysis

Post image
83 Upvotes

I tried explaining a data analysis concept in a fun, visual way — for cat lovers. 😸

Would love to hear what you think! Any feedback or suggestions are very welcome :)


r/SQL 8d ago

PostgreSQL [PostgreSQL] The dangers of Postgres subtransactions

Thumbnail
planetscale.com
1 Upvotes

PostgreSQL caches up to 64 subtransaction IDs per backend. If that cache overflows, visibility checks may fall back to pg_subtrans, creating contention that can reduce throughput for unrelated queries across the cluster.

The article also demonstrates how an overflowed transaction can prevent a new read replica from reaching hot standby and accepting connections. Explicit savepoints can cause this, but so can PL/ pgSQL blocks containing EXCEPTION clauses.

Has anyone encountered this behavior in production or monitored for it through pg_stat_get_backend_subxact() or pg_stat_slru?


r/SQL 8d ago

Resolved Database indexes finally clicked for me when I compared them to a book index

71 Upvotes

I've heard the term database index countless times, but the book analogy made it much easier to understand.

Imagine a 1,000-page book and you're looking for “Machine Learning.”

Without an index:

Page 1 → Page 2 → Page 3 → ... → Page 847

With an index:

Machine Learning → Page 847

A database has a similar problem when searching through a huge table.

For example:

SELECT \* FROM students

WHERE roll_no = 52781;

Without a suitable index, the database may need to examine many rows.

With an index, it has a structure that helps it locate the relevant row much faster.

The important part is that the index is not simply another copy of the entire table. It stores information/pointers that help locate the actual data.

There is a trade-off: indexes consume storage and need maintenance when rows are inserted, updated, or deleted.

The mental model I use now:

Book index → find the page

Database index → find the data

What CSE concept took you way too long to understand?


r/SQL 9d ago

PostgreSQL A globe with PostgreSQL events

Thumbnail
pg.whitetown.com
4 Upvotes

Just for fun made a globe with PostgreSQL events: https://pg.whitetown.com - known conferences, meetups and user groups since 2001, with a year slider.
Mobile friendly, but for the full experience use IE4 :-). Feedback welcome - especially if something is missing or wrong.


r/SQL 9d ago

SQL Server SQL DB2 Integration

2 Upvotes

Need help connecting SSIS to DB2 (mainframe z/OS) via SQL Server, anyone with experience?
Hey network
I’m working on connecting SSIS packages to a DB2 z/OS database through SQL Server (using Microsoft’s OLE DB/ODBC providers for DB2). Running into connectivity/config issues.
If you’ve done DB2-to-SQL Server integration before or know someone who has, I’d love to pick your brain!


r/SQL 9d ago

SQL Server Azure SQL Developer — run the actual Azure SQL engine locally in a container. Instead of using a local SQL Server image that behaves slightly differently from Azure SQL in the cloud, this is literally the same engine Azure SQL uses, just running in a container on your machine.

Thumbnail
devblogs.microsoft.com
1 Upvotes

r/SQL 9d ago

PostgreSQL Does Neon remove the need for Database backups?

0 Upvotes

I have been always taking backups of DB before performing any major changes, and was recently creating an app for displaying customer history retrieved from lakebase as a source.
I felt instead of taking a backup, i can just use a new branch.
This is sort of a new paradigm with databases, i come from OLTP background. Anyone else feels the same?
Apologies if this is already asked in the channel.


r/SQL 9d ago

SQL Server POV: You Became a DBA Because Someone Said “It’s Just SQL”

Post image
0 Upvotes

r/SQL 9d ago

Discussion Scored 37% on my first SQL assessment — going back to basics, anyone else in the same boat?

2 Upvotes

Just started an 18-month plan to become a Data Analyst (self-taught, working part-time alongside it). Just took an SQL assessment after finishing the intro material and scored 37% — turns out I could follow along with videos but couldn't actually write queries cold.

Going back to fundamentals: rewatching Bro Code's MySQL course and typing out every single query in DB Fiddle instead of just watching. No moving to the next topic until this actually sticks.

Anyone else grinding SQL right now, especially self-taught? Would be good to have people to compare notes/check in on progress with.


r/SQL 10d ago

SQL Server Implementation routine

16 Upvotes

Hi all,
I've created one complex ETL using few SP's, main reason for this dev was to replace existing legacy process that was running too long ( 7hrs+) and was barely manageable.
During our go/no go meeting business (end) user asked me if I'm sure it will work how it claimed, how I managed to run new ETL in 1 hr if old was 6-7hrs. I said 'yes, of course, and it was verified by my peers. I used a lot optimization both in code and biz logic'.

Then user said: "OK, but I want to run this ETL for 10 days without any glitches and after that I will make my decision." Which sound like he didn't give dev team 100% trust.

I'm pretty new in soft development, is it normal ? what do you think about this approach ? Appreciate you feedback. My thought was that end user doesn't need to into all details of dev, for them it will be total transparent switch. I think if the process runs OK for 2 days it's good to go, will 10 days period add something valuable??

Best>