3 ms·
I often do this with boolean WHERE filters when I'm doing interactive exploration on some data: SELECT ... WHERE foo = 1 AND bar = 2 I wan
by atombender 2y ago
I often do this with boolean WHERE filters when I'm doing interactive exploration on some data:
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.)
- NoMoreNicksLeft 2y agoGod, everyone's going to hate me for this. (I will have earned it, I think.) 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.
- wruza 2y agoSince we're already here, we could think about trailing AND, actually. Look: SELECT a, sum(b), WHERE foo = 1 AND GROUP BY a Sounds pretty SQL to me.
- yellowapple 2y agoThis is cursed, but also entirely consistent with the trailing comma proposal. 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
- NoMoreNicksLeft 2y agoThose aren't horrifying to me, only problem is that I want the keywords to right-align with each other.
- atombender 2y agoYou may have missed what I was getting at. 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.
- wruza 2y agoI slowly come to creating vim scripts for all that. I already use `alt-,` for triggering the final comma on a line. Maybe with modern LLMs I just need to prompt a vimscript that detects where the line is (SQL condition, array item, json, etc) and use `alt-,` to do the right thing. Or something like "fixing" the whole block with `g,ap`. Because all this is irritating and no one does anything with it for decades.
- fngjdflmdflg 2y agoHuh, I've always used "WHERE 1 = 1 AND ...". Using `true` looks more clean.
- hn1986 2y agoNot all sql variants support "true". e.g. SQL Server doesn't.
- dangets 2y agoI do the same, though my muscle memory is `1=1` instead of `true`. 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.
- refset 2y agoIn XTDB you can now use (trailing-friendly) commas in this scenario too, instead of ANDs: https://github.com/xtdb/xtdb/pull/3985 https://github.com/xtdb/xtdb/pull/3985