OP is massively overthinking it. Add them to CREATE TABLE and SELECT queries would remove 99.9% of annoyances.
How about trailing commas in SQL?
161–170 of 272 posts
Re: How about trailing commas in SQL?
#162Re: How about trailing commas in SQL?
#163Earlier 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…
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 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?
#165I 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.…
I'm not convinced this is better than what you are replacing.
Re: How about trailing commas in SQL?
#166Earlier 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.
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?
#167Re: How about trailing commas in SQL?
#168I 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…
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?
#169I 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 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?
#170I 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…
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.