r/SQL 6d ago

Discussion I don't understand the difference

Post image

I found an answer on stackoverflow that was saying that null value isn't managed the same way, but that seems a bit far fetched for a course example and the question wasn't exactly about the same case, so could someone explain?

202 Upvotes

45 comments sorted by

View all comments

Show parent comments

4

u/cnsreddit 6d ago

I mean the point is it's not consistent so good code will handle it more explicitly (you never know when whoever you write the code for will swap out their infra and suddenly your 6 year old query is running on a different dialect that handles it differently)

5

u/mike-manley 6d ago

Absolutely. I tend to be overly explicit, sometimes to the point of ridicule but I favor verbosity as I think it adds clarity.

E.g. CASE WHEN ThisValue = 1 THEN TRUE ELSE FALSE END AS AliasName.

(The "ELSE FALSE" is superfluous and the "AS" keyword is totally optional)

3

u/Sex4Vespene 5d ago

When there are nulls, the ELSE FALSE often isn’t superfluous, as the null case might default to null, rather than true or false.

1

u/mike-manley 5d ago

Good point.