Live data from Hacker News

How about trailing commas in SQL?

peter.eisentraut.org

81–90 of 272 posts

Re: How about trailing commas in SQL?

#82
post #25

Earlier quoted context omitted.

I do this as well. on top i often do a pad entry so that the elements are all on their own line SELECT 1 as pad , a , b then i can reorder lines trivially without stopping to re-comma the endpoints or maintain which special entry is on the line of the SELECT token what would be helpful is both LEADING and trailing commas so I am suggesting: SELECT , a , b would be permissible too. The parsing step is no longer the di…

Why not something like SELECT a, b, c, 1 as pad FROM Then?

cool, that would work too. my preference is leading separators so the separators are all in a visual column. being in a visual column allows the eye to discount the separators easily.

typically names are different lengths and the commas are hard/harder to spot

Your suggestion:

  SELECT
     first_column,
     second_column_wider_a_lot,
     (third + fourth_combined_expression),
  1 as pad FROM
vs my current preference:

  SELECT 1 as pad
     , first_column
     , second_column_wider_a_lot
     , (third + fourth_combined_expression)
  FROM

Re: How about trailing commas in SQL?

#83
post #5
post #2

Ugh. Why? To make copy/paste programming easier? To make query generation easier? When you're writing code to generate queries, it's worth doing it right. Just about every programming language has an easy way to take an array of strings and add a separator between each element. Like PHP's implode: implode(', ', ['foo', 'bar', 'baz']) == 'foo, bar, baz'. Every time I see a trailing comma, I think "is this a bug? did t…

To make writing and maintaining sql easier. To make sql diffs better. To make sql more consistent with other languages. Every time this trips me up, it’s hand written SQL, because literally every other language I routinely use supports trailing commas. The additional complexity during codegen is barely existent. If you’re using an orm or code generator this will be an issue once at most (if and when you write your ow…

You can already do this without changing the SQL language spec. If you really care about the things you say, follow the other comments and make the first element special which is changed much less frequently.

Re: How about trailing commas in SQL?

#85
post #5

Earlier quoted context omitted.

To make writing and maintaining sql easier. To make sql diffs better. To make sql more consistent with other languages. Every time this trips me up, it’s hand written SQL, because literally every other language I routinely use supports trailing commas. The additional complexity during codegen is barely existent. If you’re using an orm or code generator this will be an issue once at most (if and when you write your ow…

You can already do this without changing the SQL language spec. If you really care about the things you say, follow the other comments and make the first element special which is changed much less frequently.

So you can’t do it, you can do a different thing which (as I already answered in details elsewhere) still sucks but differently.

Great contribution, thanks for nothing.

Re: How about trailing commas in SQL?

#86
post #76

Earlier quoted context omitted.

That's as bad as using regular expressions: now you have TWO problems. Why do you seem to think you've cleverly solved the problem, when you've just moved the problem somewhere else just as bad, by blithely messing with the standard formatting conventions universally used by most human written languages and programming languages in the world? Programming languages borrow commas from human written languages, and no hu…

What your mind rejects, mine finds freeing. What's idiomatic and natural depends on personal experience and evolves, as does the culture around you. There was a time in my life when I may have rejected leading commas as well, but at some point I came around to them and have never looked back. It works for me. I legitimately find it easier on my mind, and it has caused me far fewer annoyances than a comma-less last co…

Leading commas are the way!

Re: How about trailing commas in SQL?

#87
post #55

> this might be the most requested feature in SQL Don’t forget to take into account the people not requesting this feature. A lot of them don’t think this is worth the changeover.

> A lot of them don’t think this is worth the changeover. I think nobody wants to make trailing commas mandatory to use

Of course not. I don't think that has anything to do with it, though.

Re: How about trailing commas in SQL?

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

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 really should account for that. And, no shade for it not already being done. I'm just reiterating that there should be NO pushback to allowing trailing commas. It's a completely "common-sense" proposal.

Re: How about trailing commas in SQL?

#90
post #17

OP is massively overthinking it. Add them to CREATE TABLE and SELECT queries would remove 99.9% of annoyances.

I get where they're coming from though. Having trailing commas work in some common cases but most other cases where there are commas would be weird and definitely result in confusion. More confusion that knowing that trailing commas aren't a thing in SQL, currently.
Post reply on HN