4 ms·
"This is an example of an anti-pattern known sometimes as "defensive programming": If something goes wrong, pretend you didn't notice and try to keep going anyw
by jeffdavis 11y ago
"This is an example of an anti-pattern known sometimes as "defensive programming": If something goes wrong, pretend you didn't notice and try to keep going anyway."
That's why SQL NULL is also a bad idea.
- tytron 11y agoHow else would you represent missing data in SQL than using nulls?
- wvenable 11y agoSQL NULLs propagate; you can't get an answer from a NULL unless you explicitly plan for it.
- nitrogen 11y agoIt can be a bit counterintuitive that "([NULL] < x)" and "NOT ([NULL] < x)" both return NULL in SQL. MariaDB [(none)]> select null as a union all select 1 as a; +------+ | a | +------+ | NULL | | 1 | +------+ 2 rows in set (0.01 sec) MariaDB [(none)]> select * from (select null as a union all select 1 as a) T where a >= 1; +------+ | a | +------+ | 1 | +------+ 1 row in set (0.00 sec) MariaDB [(none)]> select * from (select null as a union all select 1 as a) T where NOT a >= 1; Empty set (0.00 sec)
- jeffdavis 11y agoThat's false. SELECT SUM(x) FROM foo; If some x values are NULL and others not, you will never know.