by atombender · 1y ago · 0 comments
SELECT ...
WHERE
foo = 1
AND bar = 2
I want to comment out a line (i.e. "--foo = 1"), but would break the syntax.The solution is to start with "WHERE true":
SELECT ...
WHERE true
--AND foo = 1
AND bar = 2
Now you can comment/comment anything.(Putting the AND at end of each line has the same problem, of course, and requires putting a "true" at the bottom instead.)
Of course then you get editors/linters/coworkers that always point out that the 'true' is unnecessary. This also doesn't work with ORs (just swap to false), but in practice it seems it is always ANDs that is being used.
SELECT ...
WHERE foo = 1
AND bar = 2
Each keyword gets a new line, the middle gutter between keyword and expressions stays in the same place, and things get really, really fugly if I need a subselect or whatever. Any given line can be commented out. (And no, none of that leading comma bullshit, somehow that looks nasty to me.) Downvote this into oblivion to protect the junior developers from being infected by whatever degeneracy has ahold of me.In order to quickly comment out the "foo = 1" here, you cannot simply comment out the whole line because it would become syntactically invalid:
SELECT ...
--WHERE foo = 1
AND bar = 2
I have a single keyboard shortcut to comment/uncomment a line because I like to work briskly with as little unnecessary typing.It has nothing to do with indentation or being "fugly". I'm talking about interactive exploration of prototyping when the final SQL isn't set in stone.
SELECT a, sum(b),
WHERE foo = 1
AND GROUP BY a
Sounds pretty SQL to me.It'd sure look funny if all keywords that connected clauses together were trailable, though.
SELECT a, sum(b),
FROM stuff
WHERE foo = 1
OR GROUP BY a
Or just as horrifying: SELECT a, b, c,
FROM foo
UNION ALL
SELECT a, b, c,
FROM bar
UNION ALL