How about trailing commas in SQL?
81–90 of 272 posts
Re: How about trailing commas in SQL?
#82Earlier 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?
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)
FROMRe: How about trailing commas in SQL?
#83Ugh. 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…
Re: How about trailing commas in SQL?
#84Re: How about trailing commas in SQL?
#85Earlier 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.
Great contribution, thanks for nothing.
Re: How about trailing commas in SQL?
#86Earlier 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…
Re: How about trailing commas in SQL?
#87> 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
Re: How about trailing commas in SQL?
#88Prql has trailing commas https://prql-lang.org/ if you're ok with running that transformation.
Re: How about trailing commas in SQL?
#89I 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…
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?
#90OP is massively overthinking it. Add them to CREATE TABLE and SELECT queries would remove 99.9% of annoyances.