Live data from Hacker News

How about trailing commas in SQL?

peter.eisentraut.org

61–70 of 272 posts

Re: How about trailing commas in SQL?

#61
post #7

I 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.

The closing tags should be optional too.

[{},{},,,,{},,

Should be fine. Now you can push things to the eof.

Re: How about trailing commas in SQL?

#62

Earlier 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…

it is a trade-off

reordering, insertions and deletions much easier within the IDE as you’re manipulating lines as a whole. focus maintained while you are in the zone or tired is the biggest gain

at the cost of slightly uglier code and a miniscule… truly miniscule wire overhead.

other decisions will have much larger wire impact, say choosing a column wider than necessary

Re: How about trailing commas in SQL?

#63
post #23

Earlier quoted context omitted.

That’s why I use leading commas.

The first line cannot have a leading comma resulting in inconsistency then too.

That'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.

Re: How about trailing commas in SQL?

#64
post #23

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.

You’re clearly missing the entire point. The mismatched number of commas in either orientation requires you to alter unrelated fields when making modifications.

Re: How about trailing commas in SQL?

#67

OMG please please please! Regarding the author's specific questions, I would suggest not letting perfect be the enemy of good.

That'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.

Re: How about trailing commas in SQL?

#69
post #25
post #6

I 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 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?

Re: How about trailing commas in SQL?

#70
post #14
post #6

I 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…

IMHO this is one of the ugliest formattings. Whenever I see that i try to revert and avoid at all costs. I know it's a personal flavor, yet. I might be too opinionated..

I agree, I'd say I usually don't care about aesthetics, but that somehow looks so wrong, I am bothered by it.
Post reply on HN