In SQL server if you have nullParam=NULL
in a where clause, it always evaluates to false. This is counterintuitive and has caused me many errors. I do understa
Just because you don't know what two things are, does not mean they're equal. If when you think of NULL
you think of “NULL” (string) then you probably want a different test of equality like Postgresql's IS DISTINCT FROM
AND IS NOT DISTINCT FROM
From the PostgreSQL docs on "Comparison Functions and Operators"
expression
IS DISTINCT FROM
expressionexpression
IS NOT DISTINCT FROM
expressionFor non-null inputs,
IS DISTINCT FROM
is the same as the<>
operator. However, if both inputs are null it returns false, and if only one input is null it returns true. Similarly,IS NOT DISTINCT FROM
is identical to=
for non-null inputs, but it returns true when both inputs are null, and false when only one input is null. Thus, these constructs effectively act as though null were a normal data value, rather than "unknown".