4 ms·
This would work (w/ a context free grammar) if aliases required the 'AS' keyword. Ambigious: SELECT a aliasA b c aliasC FROM d aliasD e Unambigious: S
by specialist 2y ago
This would work (w/ a context free grammar) if aliases required the 'AS' keyword.
Ambigious:
SELECT a aliasA b c aliasC FROM d aliasD e
Unambigious:
SELECT a as aliasA b c as aliasC FROM d as aliasD e
Alternately, a schema-aware parser could determine if 'aliasA' was an alias or a column reference.
FWIW, personally, I'd rather go the full-Python, using newlines as delimiters:
SELECT
a aliasA
b
c aliasC
FROM
d aliasD
e
(With tabs for nesting.)
- rollcat 2y ago> FWIW, personally, I'd rather go the full-Python, using newlines as delimiters: I love Python - mostly, but significant whitespace is its worst curse, and I'd love new languages to move away from the idea. I enjoy Rust because I can write out garbage faster than I can think of it, and the auto-formatter will make it look neat. Also, have you experienced the unspeakable horror that is templating YAML files? Of course in SQL prepared statements is the safe&sane way to go, but there are cases where you still have to generate SQL as text, such as when building an ORM.
- specialist 2y agoAside: I avoid ORM hell by using SQL to generate source code.
- rollcat 2y agoI'm slowly shifting in that direction as well, but the libraries built around this style are far less mature / mainstream. Django is the "boring" solution and gets hella work done.
- wruza 2y agoWe can simply employ ACI (automatic comma insertion). Every newline after Select implies a comma, unless there’s a clearly unfinished column definition. And if you want to list columns on a single line, you have to type commas explicitly. Select Foo Foo, Bar + 1 Baz Baz Bar Quux Frob from t Table
- ars 2y agoActually it's still ambiguous, because you forgot about sub-expressions. How would you parse this: SELECT a as aliasA b select q from foo as aliasQ c as aliasC FROM d as aliasD e Even if you can figure it out (and add a 3rd level of sub-expression before deciding if you can), it's completely unreadable. You need either commas or parenthesis.