11 ms·
How about trailing commas in SQL?
- r90t 2y agoDuckDB has this feature: duckdb> select 1,2,; returns 1 and 2 https://shell.duckdb.org https://shell.duckdb.org
- oispakaljaa 2y agoAs mentioned in TFA.
- r90t 2y agoindeed
- capitanazo77 2y agoAnd by the way allow from…select Instead of select…from Its the same as having the imports first
- grantith 2y agoI wonder why this is not a thing yet. Makes a lot of sense to me as a heavy SQL user.
- elric 2y agoUgh. 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 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.
- robertlagrant 2y agoIt'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.
- croes 2y agoThat’s why I use leading commas.
- Someone1234 2y agoThe first line cannot have a leading comma resulting in inconsistency then too.
- lloeki 2y agoThat's for where the language parser allows you to have have leading commas i.e line continuations without a trailing comma. And some, amusingly, don't.
- sixothree 2y agoYou’re clearly missing the entire point. The mismatched number of commas in either orientation requires you to alter unrelated fields when making modifications.
- croes 2y agoI rarely change the beginning of the query more likely the end.
- masklinn 2y agoTo 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 own).
- wruza 2y agoTo 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?
- probably_wrong 2y agoIn my opinion: because the Robustness principle [1] is a non-insignificant cause of bugs and SQL injection is a major player in the vulnerability game. 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 https://en.wikipedia.org/wiki/Robustness_principle#Criticism [2] https://news.ycombinator.com/item?id=42999650 https://news.ycombinator.com/item?id=42999650 [3] http://www.randomprogramming.com/2014/09/quote-of-the-week-hard-things/ http://www.randomprogramming.com/2014/09/quote-of-the-week-h...
- boxed 2y agoThis doesn't seem like it's much of an argument. Injecting `d, g` on the `b` place in your example will work fine. Trailing comma or no.
- wruza 2y agoIf you write "a,b,c" you can't know whether you forgot ",d" either, because if you wanted to type ",d" but got distracted and forgot it, the habit of leaving no trailing comma will lead to just "a,b,c" without ",d". And you can't know whether you forgot or mistyped a whole query either. What is this argument even, seriously? It's so weak that it is on par with suddenly having a stroke while programming. Which guardrails should we invent for that case? SQL is fundamentally unsafe "forgot the item"-wise. It doesn't allow dynamic column selection, there's no type safety, nothing. If you want guarantees, maybe make a proper language with guarantees rather than justifying random side-effects of a comma being a syntax error sometimes.
- adornKey 2y agoI 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 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.
- DonHopkins 2y agoThat'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 human written languages have leading commas. And moving the problem to the beginning on the list because you sometimes add things to the end ignores the fact that that also causes problems with READING the code as well as writing it, and you READ code much more often than you WRITE it. That's not a solution at all, and there's nothing clever about it. You've just pushed the problem to the beginning of the list, and now your code is also butt-ugly with totally non-standard formatting, which sane people don't recognize and editors and IDEs and linters don't support. I agree with cnity that it's too clever by half, and I'm in the camp (along with Guido van Rossum and his point that "Language Design Is Not Just Solving Puzzles" [1] [2]) that's not impressed by showboating displays of pointlessly creative cleverness and Rube-Goldbergeesque hacks that makes things even worse. Of course it's not as bad as tezza's clever by a third suggestion to add a confusing throw-away verbose noisy arbitrarily named pad element at the beginning, that actually forces the SQL database to do more work and send more useless data. Now you have three or more problems. The last thing we need is MORE CODE and network traffic contributing to complexity and climate change. I would fire and forget any developer who tried to pull that stunt. [1] https://www.artima.com/weblogs/viewpost.jsp?thread=147358 https://www.artima.com/weblogs/viewpost.jsp?thread=147358 All Things Pythonic: Language Design Is Not Just Solving Puzzles. By Guido van van Rossum, February 10, 2006. Summary: An incident on python-dev today made me appreciate (again) that there's more to language design than puzzle-solving. A ramble on the nature of Pythonicity, culminating in a comparison of language design to user interface design. [...] The unspoken, right brain constraint here is that the complexity introduced by a solution to a design problem must be somehow proportional to the problem's importance. In my mind, the inability of lambda to contain a print statement or a while-loop etc. is only a minor flaw; after all instead of a lambda you can just use a named function nested in the current scope. [...] And there's the rub: there's no way to make a Rube Goldberg language feature appear simple. Features of a programming language, whether syntactic or semantic, are all part of the language's user interface. And a user interface can handle only so much complexity or it becomes unusable. [2] http://lambda-the-ultimate.org/node/1298 http://lambda-the-ultimate.org/node/1298 The discussion is about multi-statement lambdas, but I don't want to discuss this specific issue. What's more interesting is the discussion of language as a user interface (an interface to what, you might ask), the underlying assumption that languages have character (e.g., Pythonicity), and the integrated view of semantics and syntax of language constructs when thinking about language usability.
- nickcw 2y agoI 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.
- masklinn 2y agoFunny I’m the exact opposite: I essentially never write JSON by hand, or add json content to repositories, so could not care less about the lack of trailing commas, I do semi routinely write or review SQL.
- tete 2y agoI agree. And JSON basically isn't meant to be hand-written, just easy to glance over, if you need to or do basic tests with. It's a serialization format. It's not a config format or anything like that. The idea of wanting to use it for that (when the config needs to be hand-written) should be a red flag for anyone. Why would you want to hand-write something where a key is denoted with double quotes? And just to be clear: YAML is also not a config format and wasn't meant to be. YAML is for metadata style stuff that is supposed to be close to humans, heck the whole yes/no and "not so strict" typing parts. If you want a config format you got many options: There is toml/ini and friends on one side and UCL/HCL/... on the other. Or if you want to go really simple, do something like Postgres, Tor, etc. do and just use space separated strings.
- reddalo 2y ago> lack of support for trailing commas in JSON This, 100%! And the lack of comments.
- Cthulhu_ 2y agoJSON5 allows comments, it's been around since 2012. That said, JSON is not meant for humans / manual editing, and deciding to use it for configuration files was a mistake.
- deleted 2y ago[deleted]
- orf 2y agoOP is massively overthinking it. Add them to CREATE TABLE and SELECT queries would remove 99.9% of annoyances.
- jjice 2y agoI 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.
- daamien 2y agoOP is one of 7 PostgreSQL core team members. That's kind of his job to massively overthink this :)
- f4c39012 2y agoI guess trailing commas would make constructing the clauses programatically a little easier, if they are being appended one-by-one. On the downside, does this make it easier to write code that is vulnerable to command injection, because it is easier to append a bunch of statements passed as input? For the WHERE clause, if i happen to be programatically appending conditions, i'll start with `WHERE true` so i don't need to consider if i'm appending the first condition (no AND/OR/NOT etc.) or a later condition (required AND/OR/NOT etc.). A decent query planner should ignore the fixed value.
- citrin_ru 2y agoProgrammatically it is easy to not add trailing comma (just use something like `join(',', array)`) but it would save time during manual editing of a long query - I often add a new line then run query to discover that I forgot to add , on a previous line. When each line including the last one ends with , I can just add a new line (also ending with ,) and save time.
- tmpfs 2y agoI 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.
- dmurray 2y agoMost SQL implementations do seem to allow you to name a column or a table with a keyword, but to refer to it you may need to put it in quotes or backticks. I'm not sure if this is a solved problem at the level of the ANSI SQL spec or if every vendor does their own thing, but there's definitely plenty of precedent that ambiguous grammar is allowed and can be resolved.
- progmetaldev 2y agoI know that MySQL uses backticks, Postgres/Sqlite uses double quotes, and MS SQL Server uses square brackets, when using keywords for a column or table.
- Hendrikto 2y agoThe SQL standard uses double quotes.
- wruza 2y agoThe `KW item[,item]+ KW` grammar just sucks in general. Natural-ish grammars are really stupid and shortsighted.
- viraptor 2y agoPrql has trailing commas https://prql-lang.org/ https://prql-lang.org/ if you're ok with running that transformation.
- wruza 2y agoI was thinking about it again recently, but can't tell if it's worth. Have you used it in real life projects? How was it?
- viraptor 2y agoIt's nice for more complex queries. Not a big difference for simple ones. I don't have a more nuanced take here - it works fine.
- xigoi 2y agoUnfortunately it’s written in Rust, so it can only be used with Rust projects.
- coder543 2y agoIf Rust can only be used with Rust, then it's strange that the project lists a number of other languages in the docs: https://prql-lang.org/book/project/bindings/index.html https://prql-lang.org/book/project/bindings/index.html
- xigoi 2y agoAlright, it supports four languages, but that’s still not much.
- coder543 2y agoThe limitation is clearly not Rust. Any language that can bind to C libraries can bind to the functions PRQL exposes... the authors just haven't chosen to implement convenient SDKs for many languages. They also list 8 languages, not 4, just that they've had time to polish the libraries for 4 languages, apparently. PRQL appears to be a rather small project... not some major corporate effort.
- gardenhedge 2y agoThis seems so minor it's hardly worth discussing. I in the 'who cares' camp.
- boxed 2y agoThe difference between you and a single celled archea is literally only many such small "who cares" changes.
- sixothree 2y agoPeople who write code.
- jghn 2y agoHave written a lot of code over ~35 years. Not a fan of trailing commas in any language I've used.
- Supermancho 2y agoThat seems odd. The number of times you have had to correct for commas is 100% over 0% Now extrapolate to the whole industry. There's a cost, regardless of how someone might want to value it.
- trailingcoma 2y agoLmao yeah, web pages take 10+ seconds to load megabytes of JavaScript that do nothing but waste time and energy, but the SQL commas are the real culprits! What a joke.
- jmull 2y ago> 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.
- auguzanellato 2y ago> A lot of them don’t think this is worth the changeover. I think nobody wants to make trailing commas mandatory to use
- bdcravens 2y agoI'd be happy with an query editor that silently removes the comma. I write way more ad hoc SQL than what I deploy, and this would be a great tool for faster exploration of data (ditto for "FROM table SELECT columnA, ....")
- foreigner 2y agoOMG please please please! Regarding the author's specific questions, I would suggest not letting perfect be the enemy of good.
- fforflo 2y agoThat's not that easy to enforce in a system like Postgres. If you ship something you have to stay with it for many years. Thus, all possible angles have to be taken into consideration.
- fifilura 2y agoIIRC BigQuery started allowing trailing commas in queries around 2019. It all came as a very big surprise, out of thin air.
- bobchadwick 2y agoThat's correct, and I absolutely love it. If I move to a new role where BigQuery is not the data warehouse of choice, I think this will be the thing I'll miss most.
- shrikant 2y agoSnowflake also allows trailing commas :)
- morkalork 2y agoIt's nice when bigquery and python together for data analysis that little things like that are congruent
- karmakaze 2y agoI probably hand-write and generate more SQL than most. I don't find this to be anything to be concerned about--there's so much change coming soon. If I had to choose I'd opt for better editors.
- reportgunner 2y agoI feel like if you actually start writing the amount of queries where this would be useful you stop caring about tiny details like that.
- kgwxd 2y agoClojure got it right, commas are whitespace. Put them where ever you want, or don't. Problems 100% solved, and parsing is easier. Everything else seems super dumb once you see it.
- ninalanyon 2y agoWhy do we need commas?
- hbn 2y agoI've never cared for commas. I like cooking my family and my dog.
- mukunda_johnson 2y agoNo doubt the most errors in my SQL syntax when writing migrations is the extra comma.
- _blk 2y agoWhen do we get an object shell (powershell, there I said it) instead of old school strings? Been using bash for over 20y, but MS had to make it popular.. I wouldn't mind at least a proof of concept for SQL
- andy81 2y agoWhat would it offer that you can't already get from DBATools, LINQ, and ORMs more generally?
- hiccuphippo 2y agoLet me start with FROM while we are at it.
- ianmcgowan 2y agoI always start with "SELECT COUNT() FROM ..." for this reason, and then go back and replace the COUNT() when I get a handle on the tables/filters/groups involved..
- ezekiel68 2y agoI love it. I can see no downsides (as long as the updated implementations are well tested). I reject any argument about how mature SQL is at this point. Just bump the version number (SQL 25) if necessary and make it so.
- OccamsMirror 2y agoDoesn't feel like a breaking change to me.
- netcraft 2y agoI want leading _and_ trailing commas. Frequently I will be working on a query and have something like SELECT a , b , c from foo and then I want to comment out a column as I am working and exploring the data. But I cant comment out column a without also removing the comma on the next line.
- sunnybeetroot 2y agoWouldn’t just trailing solve your issue? SELECT a, b, c, From Foo
- edoceo 2y agoMoved the problem to column C
- sunnybeetroot 2y agoBut if this change is adopted, then commenting out column C would still compile the query. There isn’t a need for leading?
- netcraft 2y agoin 20 years of writing SQL, preceding commas is so much better IMO. Its so easy to miss a comma at the end of a long expression. preceding commas means you can never forget them. Then if I can have an extra leading comma, I can reorder, comment out or remove, or add a column at any point in the list without having to think about the rest of the projection. Also diffs are cleaner, it only highlights the rows that have changed, not the row above it/below it that had its comma added or removed. This happens a ton when im iterating on a query.
- nightpool 2y agoIt's only easy to miss a comma at the end of a long expression because you need to calculate whether it should be there in the first place. If commas were always required unconditionally, it wouldn't be a problem.
- innagadadavida 2y agoThis trick works for SELECT and is way less ugly than putting a leading comma. Just SELECT a constant: ‘SELECT a, b, c, 0 FROM t1 ‘
- macinjosh 2y agoAfter writing code for 20+ years these sorts of concerns are just tiresome. The effort expended debating and enforcing optimizations like this completely wipes out any and all benefits they bring, which is incredibly minimal to begin with. Just read the code, write your change, move on. If you find yourself missing small details like this you need to just slow down a tiny bit. Its not hard. By all means format your code cleanly, just don't spend cycles writing blog posts about it.
- trailingcoma 2y agoNot sure why you're being downvoted; this is the only mature, reasonable answer. This is a frivolous complaint, that would upend the SQL grammar, because someone blogged about being mildly inconvenienced. I _wish_ I had tiny, nitpicky problems like this, but my problems are actually substantial.
- yellowapple 2y agoWhy even have commas at all? This is a non-issue for the likes of Tcl and Lisp and your average shell-scripting language and what have you; whitespace is already a good enough delimiter.
- Willamin 2y agoGenuinely, I'd love to see this approach be taken: allow for a set of characters to be used as list delimiters. I personally like the set to be comma, semicolon, and newline, but of course this set would need to be varied depending on other syntax (e.g. in SQL, we wouldn't want semicolon to be used for this). Having newline be a valid list separator is particularly nice because it solves the "trailing comma" and "comma-first" style workarounds in a visually elegant way. The newline already provides a visual separator; we can already tell that we're at the end of most lists by way of having another keyword appear next without needing to rely on a lack of commas, for example: select id name email from users
- eftpotrm 2y agoBecause there's existing implementations that would interpret that as aliasing column names. ``` SELECT Field AS Renamed, OtherField AS AlsoRenamed ``` and ``` SELECT Field Renamed, OtherField AlsoRenamed ``` are semantically equivalent.
- yellowapple 2y agoMaking AS mandatory for naming columns would be an improvement in and of itself.
- eftpotrm 2y agoYes, but it's also a breaking change to a very large legacy codebase. I can't see it ever happening, sadly.
- nerdponx 2y agoBecause in SQL whitespace is already used for all manner of special syntax. That said, generating SQL from s-expressions can be a very pleasant experience.
- nightpool 2y agoDon't let the perfect be the enemy of the good. I'm sure that 99% of the people who are requesting trailing comma support care about select lists. And CREATE TABLE for the rest. Yes, the SQL standard has a huge surface area of custom syntax (rather then most programming languages which have a smaller number of composable atoms), which makes adding "consistent" syntax changes a challenge, but it doesn't mean you need to boil the ocean. Just get trailing comma select lists into a version I'm likely to use in the next decade and I will love you forever!
- nerdponx 2y agoMost of that additional syntax surface area would also benefit from trailing commas. For example, `SELECT * EXCLUDE (a, b, ...)`, or even `FROM a, b, ...`.
- taeric 2y agoReminds me of my favorite refrain that people love complaining about all of the parentheses in lisp; but completely ignore that it largely eschews all other punctuation.
- willd13 2y agoTrailing commas are an abomination
- h1fra 2y agoWithout talking about SQL it would be nice for git diff. I only see benefits of supporting them, hopefully this can be integrated into the SQL standards
- Hendrikto 2y agoAnd git blame, and it would reduce merge conflicts. Please add this.
- fragmede 2y agolast time I was on a project that involved a lot of data analysis/writing SQL, I was gonna write a plugin for "sloppy SQL" which would let me use trailing commas and some other qol features, but that project ended before I got around to it.
- gxt 2y agoAt some point we should just commit the AST to git and render it however it is preferred in IDE.
- mrighele 2y agoI 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. 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 < y -- cannot just comment this and ( z = 10 -- neither I can comment just this or baz is not null ) Yes, one could put AND and OR on their own like, but similarly one could put a comma on a line of its own...
- ars 2y agoYou want to replace comma with space or newline, and use parentheses to disambiguate subexpressions. I'm not convinced this is better than what you are replacing.
- tqwhite 2y agoPlease god. I don't believe in you but maybe someone else does and will think me a kindred spirit worthy of mercy. Let me have trailing commas. There is no reason not to. It's backward compatible, easy to implement and would make the world so so so much better.
- birb07 2y agothey are _not_ backwards compatible. That's a big part of the problem. A trailing comma is a syntax error for an SQL engine without support for it
- dhruvrajvanshi 2y agoI mean, yes, technically, but is anyone's code actually breaking because of this? Who is writing SQL queries expecting them to fail because of this reason? By your definition, "backwards compatible" doesn't mean anything. Literally everything will be a breaking change if you define "backwards compatible" like this.
- tibbar 2y agoI think the term you are looking for is "forwards compatible"! Old SQL queries will still run fine on engines that support the new syntax (they're forwards compatible.) New SQL queries with trailing commas will NOT run fine on engines that don't support trailing commas; this is not a backwards-compatible change. And that's fine.
- dhruvrajvanshi 2y ago> New SQL queries with trailing commas will NOT run fine on engines that don't support trailing commas; this is not a backwards-compatible change. But they never ran fine on engines that didn't support trailing commas in the first place :/ What you're calling "forwards compatible" is what I call "backwards compatible". Frankly, I suspect most people expect "backwards compatible" stuff to work like this. Is this distinction useful in any way?
- thehoneybadger 2y agoI nominate this post for worst idea of the century.
- tqwhite 2y agoI have to add to my huge amusement at the particulars of this thread and deep appreciation for your nerdiness. As you can see from my other post here, I consider this question to be no question at all. Obviously all SQL engines should change. Equally obviously, they never will. That all of you can take something so futile so seriously, spend time writing about your workarounds (which, of course, we all have in spades), is simply charming. Thanks for you being you.
- malkia 2y agoI really like the trailing comma, where it's supported, for that it can drive the language formatter - e.g. with trailing comma typically each item on it's own line, otherwise not. I think Dart is doing this, and other languages.
- silverwind 2y agoShould probably write a compiler that compiles "enhanced SQL" down to compatible SQL. Make it accept trailing commas, queries starting with FROM etc.
- spprashant 2y agoNot worth the trouble. This is such a cosmetic change to appease a specific type of developer but the effort to implement that across all the DB engines of note would be monumental.
- phendrenad2 2y agoOr one database can have it as an option and that "specific type of developer" can just use that?
- larrik 2y agoIt's not just cosmetic, though, as now in order to add a new entry at the end you need to change two lines of code, which means your git blame is no longer accurate.
- spprashant 2y agoLiterally unusable.
- trailingcoma 2y agoMaybe some ideas are just not good ideas.
- efitz 2y agoThere is no correct answer for this; it’s a highly personal preference. A lot of people prefer purity of grammar; these are the kind of folks who demand coding style guidelines and will be very unhappy if you violate their preference. They’re not wrong, but they have a very strong preference. A lot of people don’t care so much about particular style decisions, but they want readable code that is easy to understand, maintain and modify. I think a lot of the trailing-comma-preferring people fall into this category. But again, it’s a preference and isn’t right or wrong. There are probably also people who don’t care and compete in obfuscated code contests or try to minimize line counts by putting as many statements on each line as possible or otherwise writing genius-but-unreadable code by taking advantage of language and syntax idiosyncrasies. This is a preference too (although I consider it antisocial). My preference is, if it’s unambiguous, allow trailing commas wherever there are lists, because it makes cut and paste operations much easier. But at the end of the day that’s just my preference and not superior to anyone else.
- jaredsohn 2y agoI think the right answer is that people who care about these things should use a client that rewrites queries via an LLM and clearly show the changes it makes (not sure if this exists yet but I'm sure it will). This also would handle a few other problems I've run into such as having multiple WHERE clauses or doing a WHERE prior to a JOIN and it could also allow using plain English to describe what you want to query. I've found LLMs do a really good job of writing/cleaning up SQL.
- kdamica 2y agoOne of my favorite features of BigQuery SQL is that it accepts the trailing comma.
- johnnyballgame 2y agoTrailing commas are stupid no matter what language they are in.
- dagss 2y agoI have the complete opposite view, it is stupid to not have them. Whenever I edit JSON and SQL there is a lot of fiddling with commas when rearranging lines or adding new lines to the end of the list. In other languages I use (Go and TypeScript) there is no such fiddling.
- aoeusnth1 2y agoBecause…
- faxmeyourcode 2y agoSnowflake and DuckDB are two flavors of SQL that allow things like trailing commas. My personal favorite feature is `GROUP BY ALL`. select c1, c2, c3, ..., c50, sum(c51), from table group by all
- fsulew 2y agoI would unconsciously delete the trailing comma for a couple weeks/months.
- fjjjrjj 2y agoI'm a big fan of adding `WHERE 1=1` to the first line of a where clause. Then all remaining lines are prefixed with `AND` or `OR` which is nice for readability and indentation, and makes it easy to comment out a line while iterating.
- crazygringo 2y ago> We support most cases, except the ones that are too complicated to implement or cause grammar conflicts. It would be really helpful if the author had provided at least a couple of these. I can't think of any obvious examples that would be complicated/conflicting, so it's not even clear if this is real complexity or not. I mean, it might be, but let's at least demonstrate that concretely? SQL grammar is pretty limited. Surely it can't take more than half an hour or so to check if any grammatical ambiguities could be introduced -- or at least a quick first pass? This whole post is postulating about theoreticals when it could just answer some of them.
- kevincox 2y agoYeah, this seems like the best option. I don't get the author's confusion > Option 2 is weird, how do you determine the cutoff? The cutoff seems obvious. If it is currently always a syntax error allow a comma, if it can be valid syntax preserve the existing behaviour. I also can't think of any other cases right now, but if needed there can be a few places that don't allow trailing commas. As long as SELECT and CREATE TABLE support it 99% of the benefit will be there.
- nmstoker 2y agoWhat if they simplified it so commas were ignored and thus optional. Then they are purely for readability, allowing for whichever approach a project preferred as their standard (no commas, traditional SQL, with leading commas, with trailing conmas). I could have missed something but I don't see anything that would be impossible to parse without commas so long as there's at least one character of whitespace separation.
- sandbach 2y agoThe keyword AS would then have to be obligatory, to avoid ambiguity.
- econ 2y agoI just use an array and implode it into a string. Then can both add and remove things.
- bbstats 2y agoBigQuery supports trailing commas :)