5 ms·
Well, it would be if testing x = y produced sane results where one of those is null. I understand why SQL chooses to treat null as unknown for comparison, but
by Pxtl 11y ago
Well, it would be if testing x = y produced sane results where one of those is null.
I understand why SQL chooses to treat null as unknown for comparison, but I hate it with every fibre of my being and wish SQL dialects would join the 21st century and let me define alternate concepts of nullity like we can with modern type systems.
- letstryagain 11y agoIdeally you'd want your RDBMS to refuse to compile tests like x = y in cases where either x or y could be null. You would have to explicitly handle nulls in boolean statements.
- dllthomas 11y agoI've been working on a linter for SQL - that's probably not a bad rule to toss in the mix...
- Pxtl 11y agoThat would be sensible if SQL dialects usually offered a sane comparison that returns true/false reasonably for null comparisons. Since they don't, and = is the only available equality test, I'm going to stick to my original point that null comparison in SQL is dumb and wrong for 99% of use-cases and compiler warnings would be solving the wrong problem.
- dllthomas 11y agoMySql, Postgres, and Vertica, at least, all support <=> as an operator that treats NULL as an ordinary, distinct value.