3 ms·
What about `WHERE true`?
by hot_gril 2y ago
What about `WHERE true`?
- abrookewood 2y agoI don't understand the point at all. If you need to add some condition later on, why not just add it then? What benefit is there to just marking out the spot where you might add the condition at some point in the future?
- DH61AG 2y agoIt is a bit silly but I think it just helps with code readability some people.
- azthecx 2y agoI personally don't use it too, but I think it's origins are not just readability, but from developing queries in a REPL like environment. As you develop and are constantly creating / debugging queries where you often add new and or or clauses as a whole line, that becomes much faster to add and remove those same lines as they're a single shortcut away in nearly all text editors.
- paperplatter 2y agoYeah, so often do I have an EXPLAIN ANALYZE query.txt file I'm repeatedly editing in one window and piping into psql in another to try and make something faster. So I put WHERE true at the top.
- Izkata 2y agoFor their one here it's just the ability to rapidly comment/uncomment conditions in a query editor while exploring the data or debugging the query, and not having to worry about the leading AND or OR. I've also seen it in code with iterative adds, for example: for crit in criteria: sql += " AND " + crit No needed to add a sentinel or other logic to skip the first AND. I saw it a lot before people got used to " AND ".join(criteria).
- Izkata 2y agoI believe some database engines can be configured to error if you do that, and 1=1 doesn't trigger the safeguard.
- yen223 2y agoI've only recently learned that SQL Server doesn't have "true" or "false" (!)