How about trailing commas in SQL?
peter.eisentraut.org
How about trailing commas in SQL?
1–10 of 272 posts
Re: How about trailing commas in SQL?
#2Every time I see a trailing comma, I think "is this a bug? did they forget an element?".
Edit: as a reply to the comments below: that's a lot of hassle to save you hitting backspace once. There's premature optimization, and then there's single keystroke optimization.
Re: How about trailing commas in SQL?
#3Re: How about trailing commas in SQL?
#4Ugh. 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…
my_things = [
"thing_1",
"thing_2",
"thing_3",
]
And not have to juggle commas when you add a new end thing.Re: How about trailing commas in SQL?
#5Ugh. 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…
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 own).
Re: How about trailing commas in SQL?
#6So, my solution for this was always
SELECT a
, b
, c
FROM ...
instead of: SELECT a,
b,
c, -- people want to allow trailing comma here
FROM ...
Leading commas also are also very regular and visible. A missing trailing comma is a lot harder to see.Before people start to mess with the standard, I'd suggest to maybe just change your coding style - and make the start of the list special - instead of the end.
I'd suggest going for a lot less trailing commas - instead of allowing more.
Re: How about trailing commas in SQL?
#7What annoys me far more often is the lack of support for trailing commas in JSON.
Re: How about trailing commas in SQL?
#8Re: How about trailing commas in SQL?
#9Ugh. 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…
Re: How about trailing commas in SQL?
#10I feel like this ship has sailed. SQL has been around for more than 50 years and everyone who needs to generate it has already put that extra `if` statement in to suppress trailing commas. What annoys me far more often is the lack of support for trailing commas in JSON.