r/SQL • • 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?

35 Upvotes

103 comments sorted by

View all comments

Show parent comment

1

u/jshine13371 Jul 07 '26

Using JavaScript's == behavior for justification is... something.

It's not justification, it's for demonstration that application layer languages have similar intricacies, to argue that SQL isn't uniquely alone in this, like the person I replied to would prefer you to believe.

If FROM goes first, then auto-complete has much more context to work from. You type FROM, and it knows what can go there by looking at your schema. Once you get to SELECT, it now has the context of the FROM clause to help you auto-complete in the select clause.   With the way it actually works in SQL, your SELECT clause is referencing things in the FROM clause you haven't written yet.

I don't disagree that there are use cases for this. But to be honest, auto-completing the column names being selected are such a trivial part of the code that we've wasted more effort discussing it so far then time saved from the feature you've described.

The tooling I use already auto-expands * to the column list when I choose to, among numerous other methodologies I can just as easily use to do the same. And now with AI tooling like Copilot in SSMS, it also retroactively auto-completes for this use case too. 

Additionally, not every DQL statement has a FROM clause, but would have a SELECT clause which both makes your point about the tooling moot and explains why SELECT being the first keyword in the syntactical processing order makes more sense.

This is the weakest of points to argue for ORMs, especially when it's not even the primary goal of them, just a feature of some. Any framework or the SQL language itself can be implemented to do the same.

And I don't know why you think it'd be irrelevant.

Your example is valid and relevant, but the previous comment's unexplained point was irrelevant.