Thread: BUG #2109: NULL=NULL is false

BUG #2109: NULL=NULL is false

From
"Michał Szeląg"
Date:
The following bug has been logged online:

Bug reference:      2109
Logged by:          Michał Szeląg
Email address:      msz@szel.pl
PostgreSQL version: 7.4
Operating system:   Linux / debian sarge
Description:        NULL=NULL is false
Details:

select case when NULL=NULL then true else false end as column;

Re: BUG #2109: NULL=NULL is false

From
Michael Fuhr
Date:
On Mon, Dec 12, 2005 at 01:38:37PM +0000, Micha Szelg wrote:
> Description:        NULL=NULL is false

No, the result is NULL, not false.  See "Comparison Operators" in
the documentation:

http://www.postgresql.org/docs/7.4/interactive/functions-comparison.html

"Do not write expression = NULL because NULL is not 'equal to' NULL.
(The null value represents an unknown value, and it is not known
whether two unknown values are equal.)"

You could change the behavior with the transform_null_equals
configuration setting, but as the documentation says, "this option
is not a general fix for bad programming."  It would be better to
use standard-conforming expressions such as IS DISTINCT FROM (standard
since SQL:1999, as I recall).

test=> SELECT NULL = NULL;
 ?column?
----------

(1 row)

test=> SELECT NULL IS DISTINCT FROM NULL;
 ?column?
----------
 f
(1 row)

--
Michael Fuhr