Postgres's lateral joins allow for quite the good eDSL

A nerdy database trick just sparked a raw SQL vs ORM feelings war

TLDR: The post argues a little-known PostgreSQL feature can make database questions more reusable and less painful to build. Commenters promptly turned that into a dramatic fight over whether helper tools are genius or garbage, with plenty of jokes about just writing raw SQL yourself.

A quiet little database feature just accidentally unleashed big opinions. The original post says a lesser-known PostgreSQL trick called a “lateral join” can make building reusable database queries way easier. In plain English: it’s a smarter way to ask a database for connected information, and the author argues it could help developers avoid the usual pain of clunky tools that try to write database code for them.

But the real fireworks were in the comments. One camp basically yelled, just write the database language yourself. The thread’s most quote-worthy moment came from a commenter recalling a co-worker asking, “you scared to rawdog sql or something” — instantly giving the whole debate the energy of a group chat turning feral. That anti-ORM mood was strong: several people piled on the idea that fancy helper tools often create more mess than they solve.

Still, not everyone was there for the anti-tool dogpile. Some chimed in with “we’ve been doing this already,” pointing to other systems and older workarounds, while another person hit the brakes with the most relatable complaint of all: please explain the acronym first. Honestly? Fair. There was also a practical grown-up in the room saying this trick is genuinely useful for turning messy JSON data into tidy tables.

So yes, the post is about a clever database shortcut — but the comments turned it into a full-blown showdown over whether developers should embrace clever abstractions, or stop being cowards and type the query themselves.

Key Points

  • The article explains that PostgreSQL lateral joins let subqueries in the FROM clause reference columns from earlier FROM items.
  • A standard join between `users` and `posts` is rewritten as a `CROSS JOIN LATERAL` example with equivalent filtering behavior.
  • The article shows the standard join and the lateral join producing the same query plan in the given example.
  • It argues that lateral joins can improve query composability for an eDSL compared with common ORM and query-builder patterns.
  • The article defines goals for such a query builder: expressiveness, composability, type safety, valid SQL generation, and support for user-defined types.

Hottest takes

"you scared to rawdog sql or something" — trueno
"You should probably tell us at the start of the article what eDSL is." — brikym
"With lateral join queries form a lawful monad." — anon291
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.