Earlier quoted context omitted.
It's so you can do this in code: my_things = [ "thing_1", "thing_2", "thing_3", ] And not have to juggle commas when you add a new end thing.
That’s why I use leading commas.
How about trailing commas in SQL?
31–40 of 272 posts
Re: How about trailing commas in SQL?
#32Re: How about trailing commas in SQL?
#33I 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've moved the problem from the last to the first element though. Surely people would prefer to be able to do this SELECT a, b, c, FROM ... ?
SELECT 1 as pad
, a
, bRe: How about trailing commas in SQL?
#34Earlier quoted context omitted.
During prototyping, I'm frequently adding and removing entries from lists, or change their order. It's really annoying when you have to update the commas afterwards. Much nicer dev experience when ever entry ends with a comma, and you can juggle them around at will.
That’s why I use leading commas. Unless I change the first column, no problem.
When you stop working with any other code than SQL you look back on your younger self and think ‘I was soooo young’ when typing those lovely leading commas.
Re: How about trailing commas in SQL?
#35DuckDB has this feature: duckdb> select 1,2,; returns 1 and 2 https://shell.duckdb.org
Re: How about trailing commas in SQL?
#36I suspect that it's perfectly valid to name a column "from" or any other SQL keyword so allowing a trailing comma would make the grammar ambiguous. Personally I agree with the sentiment, I find it annoying to have to juggle the commas on the last column name but I think there is likely a valid reason to do with making lexing easier to reason about.
Re: How about trailing commas in SQL?
#37Prql has trailing commas https://prql-lang.org/ if you're ok with running that transformation.
Re: How about trailing commas in SQL?
#38Earlier quoted context omitted.
That’s why I use leading commas. Unless I change the first column, no problem.
When you start working with sql you despise leading commas. When you stop working with any other code than SQL you look back on your younger self and think ‘I was soooo young’ when typing those lovely leading commas.
Re: How about trailing commas in SQL?
#39Earlier quoted context omitted.
When you start working with sql you despise leading commas. When you stop working with any other code than SQL you look back on your younger self and think ‘I was soooo young’ when typing those lovely leading commas.
That sounds made up on the spot. I wrote leading commas in SQL for decades, no such thought crossed my mind. I still use and suggest them to people. They look especially good when aligning selected columns.
Learned to love the functionality of these though and the looks grew on me.
Re: How about trailing commas in SQL?
#40To this still empty thread: how about we just stop arguing and add these damn commas everywhere? How about having human- and devenv-oriented languages finally, after how many decades?
The first case that jumps to me: if you write "a,b,c," you can't know whether you forgot a parameter, you passed an empty string where there shouldn't be one, or you intentionally left a trailing comma. And SQL already is human-oriented - compare your typical SQL to a data operation in K [2]. It just so happens that some things are hard and off-by-one errors are famously near the top of the list [3].
Whenever a database complains that your SQL query contains a trailing comma it's a sign that you may not have paid enough attention to your arguments (or even worse, that you're building queries by hand instead of using prepared statements). From where I stand, not allowing trailing commas is a feature, not a bug, and I would therefore object against them.
[1] "be conservative in what you do, be liberal in what you accept from others" - https://en.wikipedia.org/wiki/Robustness_principle#Criticism
[2] https://news.ycombinator.com/item?id=42999650
[3] http://www.randomprogramming.com/2014/09/quote-of-the-week-h...