3 ms·
If I could make one change to SQL, it would be to put the FROM clause before the SELECT clause. This would make it so much easier to do good autocompletion.
by mayoff 9y ago
If I could make one change to SQL, it would be to put the FROM clause before the SELECT clause. This would make it so much easier to do good autocompletion.
- tveita 9y agoRequiring the WHERE clause in DELETE FROM would probably have avoided some very expensive disasters, too... I'll just come out and say it, modern SQL amazing and powerful but it is not a good language. The language spec shows a weird obsession with "natural language" style programming, sometimes at the cost of safety, consistency and expressiveness. It is not a good language to generate by code, nor to use directly on the command line. It is not a good language to efficiently access your stored data, nor to express relational algebra. But you're going to have to learn it, and modern databases do amazing things with it to make it work.
- garyclarke27 9y agoAgreed, I've always thought this, CTE's kind of do this, but unfortunately Postgres does not optimise them (one of it's few failings). The SQL standard should be changed to optionally allow FROM to come first. SQl is amazingly powerful, sometimes over verbose though e.g windows functions. Also Natural join should be improved, with an option to use Foreign Keys to determine columns to join on, instead of just common column names which can be risky.
- dangoldin 9y agoIt makes sense for the simple case but I can see it getting a bit hairy if you're doing a variety of joins. Then it would be FROM X join Y on .. join Z on .. join (..) as T SELECT X.A, Y.B WHERE .. I guess it's jarring but that's due to me not being used to it. Some people prefer doing joins using there where clause in which case the FROM ends up being in closer to location to the WHERE.
- combatentropy 9y agoI have thought the same thing, because it would match the order of other statements (insert, update, and delete) which begin with the source. In fact I would put the select after the where clause: from t where x = 'y' select a, b, c order by a, b, c
- kedean 9y agoThe problem with that order is that where often depends on what has been selected. If you select max(a) as ma, you should know that before you try to compare it to something.
- combatentropy 9y agoThis doesn't work, at least in PostgreSQL: select b, max(a) as ma from t group by b where ma > 100 ERROR: column "ma" does not exist You would have to use the having clause: select b from t group by b having max(a) > 100