Ever seen code like this?


select *
from   EMP
where  1=1
and    sal > 10
and    dept_no = 20

You would probably wonder: Why is there a “WHERE 1=1” predicate? Surely that does nothing?

And you would be absolutely right…IT DOES NOTHING. I should clarify – it does nothing, if you were referring to the optimizer.

But to me, it doesn’t do nothing. It does one thing and that one thing is tell me there’s a developer on the team who isn’t getting a Christmas card 🤣

I mean … c’mon man. Why pollute your SQL with predicates you don’t need? I see people justifying it with:

“Oh, when I am dynamically adding predicates I can just use ‘AND’ for all of them”.

Seriously? You know what that tells me? It tells me you can’t count, because here you are – entrusted to building enterprise grade applications for customers, whilst also probably charged with the security of their data and you’re telling me its too much trouble to know if you are dealing with the first predicate versus the subsequent ones?

Not only does it tell me you can’t count, it tells me that you can’t count TO ONE ! 🤣

And even if there was some tiny sliver of benefit to having it when you are dynamically adding predicates, it behooves me to ask

  1. Why is our app dynamically adding predicates all over the place? That sounds like a requirements/design concern to me, not an excuse to slam “1=1” everywhere.
  2. How on earth did that lead to adding it to static SQL in your application? What the heck is that about?

Don’t bother coming at with your “It’s practical”, “It makes coding easier”, “I can comment it out easier”. I’m not buying that for a moment, because in the same breath you’ll be telling me we need to dedicate sprint 17 of our next build cycle to refactoring the code base to remove redundant code from the Java layer, all while you’re slamming an extra line of SQL into every database access you make! 🤣

So next time you see this code


select *
from   EMP
where  1=1
and    sal > 10
and    dept_no = 20

I think you should refactor it to be


select *
from   EMP
where  1=1
and    2=2
and    sal > 10
and    dept_no = 20

and the next time after that


select *
from   EMP
where  1=1
and    2=2
and    3=3
and    sal > 10
and    dept_no = 20

select *

and so on. I mean, how are the fans of “1=1” going to criticise that? “Hey, you added some redundant code?” LOL… You started it! 🤣

Ho Ho Ho! Merry Christmas! Or maybe BAH HUMBG is a better sign off for this post 🤣

5 responses to “Kris Kringle the Database – Friday RANT”

  1. ❤️❤️❤️

  2. If it matters to you so much then why do you use redundant spaces? Why three spaces between FROM and the table name? Why four spaces between AND and a predicate? Why do you pick and choose what is redundant and what isn’t?Should all of us follow this example and pedantically criticize minor details of everyone else’s code? Should I discriminate against you because you use extra spaces and I don’t?Or should I just let this go and judge you by the bulk of your work and wish you a very Merry (and hopefully not to hot in Australia) Christmas despite your commitment to using all of those extra spaces? 🙂

  3. Yeah, no kidding. This has always been a pet peeve of mine.

Leave a reply to graht1 Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trending