Re: BUG #2178: NOT IN command don't work

From: Reece Hart <reece(at)harts(dot)net>
To: Daniel Afonso Heisler <daniel(at)solis(dot)coop(dot)br>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2178: NOT IN command don't work
Date: 2006-01-24 04:08:38
Message-ID: 1138075718.7081.81.camel@tallac.gene.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, 2006-01-17 at 22:00 +0000, Daniel Afonso Heisler wrote:
> But, when i run the next query, it don't return TRUE
> # SELECT true WHERE 1 NOT IN (2,NULL,3);

These are not bugs.

The first statement is equivalent to

# select true where (1 != 2) and (1 != NULL) and (1 != 3);

1 != NULL is itself NULL (not false!). Similarly, TRUE AND NULL AND
TRUE evaluates to NULL, and therefore you've really written

# select true where NULL;

which, of course, should and does print nothing.

Your second query
# SELECT true WHERE 1 IN (1,2,NULL,3);

is equivalent to
# select true where (1=1) or (1=2) or (1=NULL) or (1=3);

which should and does return true.

Try these:
# select 1=1 and null;
# select 1=1 or null;
# select 1!=1 and null;
# select 1!=1 or null;

For more info, google for `sql not in NULL'. You'll see references like
http://www.metrokc.gov/gis/kb/Content/SQLTipNull.htm

-Reece

--
Reece Hart, Ph.D. rkh(at)gene(dot)com, http://www.gene.com/
Genentech, Inc. 650-225-6133 (voice), -5389 (fax)
Bioinformatics and Protein Engineering
1 DNA Way, MS-93 http://harts.net/reece/
South San Francisco, CA 94080-4990 reece(at)harts(dot)net, GPG:0x25EC91A0

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message RIMBAUD Christophe 2006-01-24 10:35:22 BUG #2206: error on declare cursor after a close cursor
Previous Message agattik 2006-01-24 03:23:43 BUG #2205: Compilation error on Tru64: socklen_t in pqcomm.c