Skip site navigation (1) Skip section navigation (2)

Re: BUG #2109: NULL=NULL is false

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: MichaÅ SzelÄg <msz(at)szel(dot)pl>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2109: NULL=NULL is false
Date: 2005-12-14 01:35:02
Message-ID: 20051214013502.GA28021@winnie.fuhr.org (view raw or flat)
Thread:
Lists: 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

In response to

pgsql-bugs by date

Next:From: Tom LaneDate: 2005-12-14 04:07:25
Subject: Re: BUG #2111: Error parsing 'infinity' under some versions of glibc
Previous:From: Jim DewDate: 2005-12-13 23:46:53
Subject: BUG #2112: query kills db thread

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group