Live data from Hacker News

How about trailing commas in SQL?

peter.eisentraut.org

161–170 of 272 posts

Re: How about trailing commas in SQL?

#163

Earlier quoted context omitted.

Adding something to the end is the most common thing to do. And changing the start is extremely rare - it's anyway special because you usually put it in the line with the SELECT.

> you usually put it in the line with the SELECT. No, you usually don't. That would "bury" the first field so you don't immediately see it if you quickly glance at the code. I'll admit I was a bit surprised when I saw a fully formatted SQL query but it does look much better: SELECT a, b, c, d FROM Customers ORDER BY b, c DESC Edit: I've just seen other comments here suggesting you return an extra "pad" value at the s…

Any new style will look bad, simply because it is new to us. But you quickly get used to it.

After that, it is about minimizing errors. Leading commas minimize errors, and is a style that is portable across databases.

Re: How about trailing commas in SQL?

#164
I don't think this is something that warrants such a change, but if I had a choice I would prefer to be able to completely avoid using comma, maybe just by using an extra pair of parenthesis. I this would break in more than one way, but one can dream.

   SELECT (a b c) from sometable where id in (10 20 30)
This would be quite useful when doing exploratory work and you want also to copy/paste values from somewhere else.

But to be fair the main issue in this case is handling of the WHERE clause, because (un)commenting parts is never straightforward

    select foo from bar 
    where
      x 
Yes, one could put AND and OR on their own like, but similarly one could put a comma on a line of its own...

Re: How about trailing commas in SQL?

#165

I don't think this is something that warrants such a change, but if I had a choice I would prefer to be able to completely avoid using comma, maybe just by using an extra pair of parenthesis. I this would break in more than one way, but one can dream. SELECT (a b c) from sometable where id in (10 20 30) This would be quite useful when doing exploratory work and you want also to copy/paste values from somewhere else.…

You want to replace comma with space or newline, and use parentheses to disambiguate subexpressions.

I'm not convinced this is better than what you are replacing.

Re: How about trailing commas in SQL?

#166

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…

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
      e
(With tabs for nesting.)

Re: How about trailing commas in SQL?

#167
Please god. I don't believe in you but maybe someone else does and will think me a kindred spirit worthy of mercy. Let me have trailing commas. There is no reason not to. It's backward compatible, easy to implement and would make the world so so so much better.

Re: How about trailing commas in SQL?

#168
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…

ClickHouse has support for trailing commas for several years.

I recommend looking at ClickHouse (https://github.com/ClickHouse/ClickHouse/) as an example of a modern SQL database that emphasizes developer experience, performance, and quality-of-life improvements.

I'm the author of ClickHouse, and I'm happy to see that its innovation has been inspired and adopted in other database management systems.

Re: How about trailing commas in SQL?

#169
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. You are on the wrong side of history.

Re: How about trailing commas in SQL?

#170
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…

Alternately:

  SELECT a, b, c, NULL FROM ...

  SELECT a, b, c, true FROM ...

  SELECT a, b, c, 'ignore me' FROM ...
FWIW, my SQL grammar ignores trailing commas. IIRC, H2 Database does too.
Post reply on HN