Re: BUG #2109: NULL=NULL is false - Mailing list pgsql-bugs

From Michael Fuhr
Subject Re: BUG #2109: NULL=NULL is false
Date
Msg-id 20051214013502.GA28021@winnie.fuhr.org
Whole thread Raw
In response to BUG #2109: NULL=NULL is false  ("Michał Szeląg" <msz@szel.pl>)
List pgsql-bugs
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

pgsql-bugs by date:

Previous
From: "Michał Szeląg"
Date:
Subject: BUG #2109: NULL=NULL is false
Next
From: Tom Lane
Date:
Subject: Re: BUG #2111: Error parsing 'infinity' under some versions of glibc