Live data from Hacker News

How about trailing commas in SQL?

peter.eisentraut.org

191–200 of 272 posts

Re: How about trailing commas in SQL?

#192
post #3

To this still empty thread: how about we just stop arguing and add these damn commas everywhere? How about having human- and devenv-oriented languages finally, after how many decades?

How about we just do nothing and people write syntactically-correct SQL instead of demanding everyone and everything else change? I'm sorry, is this really the most important impediment to software development right now? Some guy's beef with the SQL parser?

Re: How about trailing commas in SQL?

#193

Earlier quoted context omitted.

I don't want to write commas at all. I want to write SELECT a b c FROM d Or even SELECT a b c FROM d Because now selected values are uniform and there's no superfluous punctuation to worry about.

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…

We 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

Re: How about trailing commas in SQL?

#194

Not worth the trouble. This is such a cosmetic change to appease a specific type of developer but the effort to implement that across all the DB engines of note would be monumental.

Or one database can have it as an option and that "specific type of developer" can just use that?

Re: How about trailing commas in SQL?

#195

Earlier quoted context omitted.

That is the haskell workaround, and it also sucks, because it still requires a special non-uniform first value. I do not want to write either of your snippets, I want to write SELECT a, b, c, FROM Because now selected values are uniform and I can move them around or add new ones with minimal changes no matter their position in the sequence . It’s also completely wonky in many contexts e.g. CREATE TABLE. Trailing comm…

Spot on. Also, to generalize a bit: if a human is expected to read it, the way humans write should be able to be parsed by it. That's subjective, to a point, but it's an easy rule-of-thumb to remember. Trailing commas are so common that people have built workarounds for them. Therefore, they can be understood as "the way humans write". If you're writing a language that you still want to be readable by humans, you rea…

> It's a completely "common-sense" proposal.

The SQL standards committee is having none of it. I can tell you that just from this one sentence.

And, more seriously, there isn't really such a thing as a common-sense proposal with SQL. The grammar is so warped after all these years that there isn't a path to consistency and the broken attempt at English syntax has rendered it nearly incomprehensible for both human and machine parsing. Any change to anything could have bizarre flow on effects.

I'd love to see trailing commas added to SELECT though. Given the mess it isn't possible to make the situation worse and the end of the list being special can be infuriating.

Re: How about trailing commas in SQL?

#196
post #6

I feel the problem. When coding (not only in SQL) you often have to add something to the end of a list, and it is annoying that the end of the list is always special. You can't just copy some line and move it there. Also when moving things around you always have to take extra care at the end. So, my solution for this was always SELECT a , b , c FROM ... instead of: SELECT a, b, c, -- people want to allow trailing com…

You are a monster. Being against trailing commas is like being against happiness or cute children or Cheetohs. You do not need to see the missing comma. That is what compilers are for. Also, literally the only reason anyone has a missing comma is because they reordered the terms and forgot to put the comma onto the one that was forced to not have one because of this monstrous failure. Some things are nothing but good…

One thing I like about the nix language is it uses semicolons to separate elements of the map: while I use trailing commas, they always look dangling to me whereas semicolons look fine without another expression following.

Re: How about trailing commas in SQL?

#197

Earlier quoted context omitted.

I don't want to write commas at all. I want to write SELECT a b c FROM d Or even SELECT a b c FROM d Because now selected values are uniform and there's no superfluous punctuation to worry about.

You can get either commas or required `as` and parenthesis around expressions. IMO, required `as` and parenthesis are better. But it's not a clear thing where everybody will agree.

Ideally there'd be a syntax that looked like a function `SELECT(a, b, c, d)` with a totally distinct variant for specifying types `TSELECT(a, int, b, null, c, text, d, timezonetz)`.

The big problem here is the seemed-good-in-the-70s syntax that died with SQL. In the best of all possible worlds they could have just used Lisp as the foundation then let people macro/transpile their own syntaxes. A subtle flaw in SQL is being just hard enough to correctly emit that most people don't build new languages on top of it.

Re: How about trailing commas in SQL?

#198

After writing code for 20+ years these sorts of concerns are just tiresome. The effort expended debating and enforcing optimizations like this completely wipes out any and all benefits they bring, which is incredibly minimal to begin with. Just read the code, write your change, move on. If you find yourself missing small details like this you need to just slow down a tiny bit. Its not hard. By all means format your c…

Not sure why you're being downvoted; this is the only mature, reasonable answer. This is a frivolous complaint, that would upend the SQL grammar, because someone blogged about being mildly inconvenienced. I _wish_ I had tiny, nitpicky problems like this, but my problems are actually substantial.

Re: How about trailing commas in SQL?

#200
post #84

Earlier quoted context omitted.

Have written a lot of code over ~35 years. Not a fan of trailing commas in any language I've used.

That seems odd. The number of times you have had to correct for commas is 100% over 0% Now extrapolate to the whole industry. There's a cost, regardless of how someone might want to value it.

Lmao yeah, web pages take 10+ seconds to load megabytes of JavaScript that do nothing but waste time and energy, but the SQL commas are the real culprits!

What a joke.

Post reply on HN