r/SQL • u/yughiro_destroyer • Jul 06 '26
Discussion Why do we need abstractions over SQL?
When I mean abstractions, I mainly mean OOP and ORMs.
SQL is so simple and beautiful. Tables with rows and columns are easy to understand. And once you pick up the SQL syntax, you can pretty much achieve anything with queries. Not to mention that SQL is universal and works everywhere and anytime.
Then you have the software development world... where you're asked to constantly use ORMs or map records as OOP objects. Why? ORMs are limited and do not have the flexibility of simple queries. Also mapping records as objects increases bloat, reduces performance that can hurt if the application grows and is overall not as straightforward to work with.
The only good things that ORMs are doing by default are to provide data safety and prevent SQL injection. But with some minimum and basic knowledge and discipline, you can write pure queries without having those problems. Any ideas?
View all comments
Show parent comment
1
u/xenomachina Jul 07 '26
Using JavaScript's
==behavior for justification is... something. Javascript's==behavior is generally considered very weird, and one of its biggest warts.That SQL doesn't have
NULL = NULLreturnTRUEis also very weird. It's a product of its time. Nobody who knows anything about programming language design would design a language with this behavior in 2026. It makes reasoning harder, complicates optimization, and is an extremely surprising behavior to most people familiar with programming languages other than SQL. The fact that these other operations (DISTINCT, etc.) treat twoNULLs as identical, while=insistsNULL = NULLisUNKNOWN, shows the language can't even keep itsNULL-equality story straight.Your counterargument, that you'd prefer
SELECTfirst, is subjective, but the fact thatFROM-first enables better tooling is not:If
FROMgoes first, then auto-complete has much more context to work from. You typeFROM, and it knows what can go there by looking at your schema. Once you get toSELECT, it now has the context of theFROMclause to help you auto-complete in the select clause.With the way it actually works in SQL, your
SELECTclause is referencing things in theFROMclause you haven't written yet.And I don't know why you think it'd be irrelevant. The question under discussion is "Why do we need abstractions over SQL?", and one of the things that many abstractions over SQL do is allow from-first queries precisely because it enables better tooling.