Re:Handling Null Values in Postgres
by ainar-g on Thursday March 05, 2020 @12:41PM
(#22495912)
They forgot "IS NOT DISTINCT FROM", which is, IMHO, the best god damn
operator ever invented. It works like "=", but adequately responds to
NULL:
[ Parent
| on HN ]
Came here to say the same thing. An article about NULL without even a passing mention of IS DISTINCT FROM is embarrassing.
Truth table here: https://wiki.postgresql.org/wiki/Is_distinct_from#Truth_Tabl...
Re:Handling Null Values in Postgres
by kingdomcome50 on Thursday March 05, 2020 @12:57PM
(#22496099)
Wait... You don't like:
`ISNULL(NULLIF(A, B), NULLIF(B, A)) IS NULL`
What are you? human?
Re:Handling Null Values in Postgres
by pavel_lishin on Thursday March 05, 2020 @04:58PM
(#22498800)
Oh my god. We had a bug awhile back due to null equality comparison treating nulls as non-equal; I wish I'd known about mysql's equivalent ("<=>") back then!
Actually this blog is not about how many ways you can use NULL in the database. It's all about the people who have programming experience (C/C++/JAVA) and try to write the SQL queries.
Re:Handling Null Values in Postgres
by carterehsmith on Thursday March 05, 2020 @09:53PM
(#22500630)
"SELECT NULL IS NOT DISTINCT FROM NULL"
?column?
----------
t
That bothers me. It is like saying that "infinity" (+inf) equals other infinity. Which is just wrong.
Some other SQL dialects will return "UNKNOWN" rather than "t" (true), which imho makes way more sense.
...I think you are misunderstanding the whole reason for the IS NOT DISTINCT FROM operator, which is exactly that.
"SELECT NULL = NULL" will return NULL, use that if you want the standard way. There are many cases where you want it to return true though, and the boilerplate for that sucks, so IS NOT DISTINCT FROM has a very useful place in the dialect.