News for hackers. Stuff that matters.
Re:Pipe Syntax in SQL by thiht on Saturday August 24, 2024 @02:38PM (#41340378)
Honestly SQL screwed things up from the very beginning. "SELECT FROM" makes no sense at all. The projection being before the selection is dumb as hell. This is why we can’t get proper tooling for writing SQL, even autocompletion can’t work sanely. You write "SELECT", what’s it gonna autocomplete?

PRQL gives me hope that we might finally get something nice some day

Re:Pipe Syntax in SQL by scrlk on Saturday August 24, 2024 @04:14PM (#41341148)
The initial version of SQL was called "Structured English Query Language".

If the designers intended to create a query language that resembled an English sentence, it makes sense why they chose "SELECT FROM."

"Select the jar from the shelf" vs. "From the shelf, select the jar".

Re:Pipe Syntax in SQL by xigoi on Sunday August 25, 2024 @05:29AM (#41345875)
“Go to the shelf and select the jar”. You’re describing a process, so it’s natural to formulate it in chronological order.
Re:Pipe Syntax in SQL by mr_toad on Thursday August 29, 2024 @12:40AM (#41387375)
SQL is a declarative language not a procedural one. You tell the query planner what you want, not how to do it.
Re:Pipe Syntax in SQL by parpfish on Saturday August 24, 2024 @04:07PM (#41341093)
I also hate having SELECT before FROM because I want to think of the query as a transformation that can be read from top to bottom to understand the flow.

But I assume that that’s part of why they didn’t set it up that way — it’s just a little thing to make the query feel more declarative and less imperative

Re:Pipe Syntax in SQL by akira2501 on Saturday August 24, 2024 @02:39PM (#41340383)

    SELECT 1+2;
FROM clauses aren't required, and using multiple tables in FROM doesn't seem to work out too well when that syntax is listed first.
Re:Pipe Syntax in SQL by yen223 on Saturday August 24, 2024 @03:56PM (#41341005)
WITH clauses are optional and appear before SELECT. No reason why the FROM clause couldn't behave the same
Re:Pipe Syntax in SQL by akira2501 on Saturday August 24, 2024 @04:45PM (#41341348)
Isn't that strictly for CTEs? In which case, you are SELECTing from the CTE.
Re:Pipe Syntax in SQL by ElectricalUnion on Sunday August 25, 2024 @12:48AM (#41344465)
Beginning with Oracle Database Release 23 [released May 2, 2024], it is now optional to select expressions using the FROM DUAL clause.
Re:Pipe Syntax in SQL by thiht on Sunday August 25, 2024 @04:54AM (#41345694)
Doesn’t change anything, you can still have the select at the end, and optional from and joins at the beginning. In your example, the select could be at the end, it’s just that there’s nothing before.
Re:Pipe Syntax in SQL by gfody on Saturday August 24, 2024 @02:56PM (#41340532)
> what’s it gonna autocomplete?

otoh if you selected something the from clause and potentially some joins could autocomplete

Re:Pipe Syntax in SQL by thiht on Sunday August 25, 2024 @04:57AM (#41345709)
Not reliably, especially if you alias tables. Realistically, you need to know what you’re selecting from before knowing what you’re selecting.