News for hackers. Stuff that matters.
Re:SQL Tips and Tricks by abrookewood on Wednesday September 25, 2024 @04:06AM (#41644953)
I 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?
Re:SQL Tips and Tricks by DH61AG on Wednesday September 25, 2024 @04:16AM (#41645012)
It is a bit silly but I think it just helps with code readability some people.
Re:SQL Tips and Tricks by azthecx on Wednesday September 25, 2024 @06:10AM (#41645669)
I 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.

Re:SQL Tips and Tricks by paperplatter on Wednesday September 25, 2024 @12:16PM (#41649021)
Yeah, 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.
Re:SQL Tips and Tricks by Izkata on Wednesday September 25, 2024 @09:02AM (#41647002)
For 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).
Re:SQL Tips and Tricks by regexman1 on Wednesday September 25, 2024 @09:18AM (#41647187)
That's right - it's just a quicker way of being able to comment/uncomment conditions when doing EDA or debugging.
Re:SQL Tips and Tricks by hot_gril on Wednesday September 25, 2024 @02:48PM (#41650642)
Yeah. Especially when I'm trying to see what makes some query slow.