News for hackers. Stuff that matters.
Re:Best practices for writing SQL queries by Hjfrf on Saturday April 10, 2021 @01:14PM (#26763113)
Does that still look ok if you're selecting 10+ columns with functions, or would you split out the first line situationally?
Re:Best practices for writing SQL queries by hn_throwaway_99 on Saturday April 10, 2021 @01:19PM (#26763155)
Another commenter showed how this works:

  SELECT a.foo
       , b.bar
       , g.zed
    FROM ...
While the comma placement may seem weird, it makes this exactly identical to the "AND" or "OR" placement in WHERE clauses, and the primary benefit is that it's easy to comment out any column except the first.
Re:Best practices for writing SQL queries by mulmen on Saturday April 10, 2021 @04:34PM (#26764901)
It's always easy to comment out any column except the first or last. Leading commas make it easy to comment out the last column, trailing commas make it easy to comment out the first.

Personally I don't think that optimization is worth the price. Trailing commas look nicer visually so I prefer them.

Re:Best practices for writing SQL queries by jolmg on Saturday April 10, 2021 @03:50PM (#26764489)
> While the comma placement may seem weird

It's not completely unconventional. Haskell is typically styled with that kind of comma usage, too. For example,

  [ 1
  , 2
  ]

  { foo = 1
  , bar = 2
  }
Coincidentally, SQL and Haskell are the only languages I know that use `--` for comments.
Re:Best practices for writing SQL queries by Wevah on Saturday April 10, 2021 @07:08PM (#26766115)
FWIW, Lua and AppleScript (and HyperTalk!) use(d) `--` as well.

(Edit: I think I misread “know” as “know of”; whoops.)

Re:Best practices for writing SQL queries by jolmg on Monday April 12, 2021 @12:59PM (#26781869)
> I think I misread “know” as “know of”; whoops.

Don't worry about it; you didn't misread. I wasn't aware of AppleScript and HyperTalk, and though I read a bit on Lua some years ago, I either forgot or never realized that it used `--` for comments.

Re:Best practices for writing SQL queries by mulmen on Saturday April 10, 2021 @04:35PM (#26764909)
With the curly braces this makes a lot more sense. In SQL it offends my eyes (personal preference) but here it seems more clear.