pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
NULL in IN clause
5+ messages / 5 participants
[nested] [flat]

* NULL in IN clause
@ 2005-10-19 20:17  =?iso-8859-2?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu>
  0 siblings, 4 replies; 5+ messages in thread

From: Havasvölgyi Ottó @ 2005-10-19 20:17 UTC (permalink / raw)
  To: pgsql-sql

Hi,

I have just run this command on 8.0.4 :

SELECT 'foo' WHERE 0 NOT IN (NULL, 1);

And it resulted is zero rows.
Without NULL it is OK.
Is this a bug, or the standard has such a rule?

Best Regards,
Otto





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: NULL in IN clause
@ 2005-10-19 20:41  Terry Fielder <terry@ashtonwoodshomes.com>
  parent: =?iso-8859-2?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu>
  3 siblings, 0 replies; 5+ messages in thread

From: Terry Fielder @ 2005-10-19 20:41 UTC (permalink / raw)
  To: Havasvölgyi Ottó <h.otto@freemail.hu>; +Cc: pgsql-sql



Havasvölgyi Ottó wrote:
> Hi,
> 
> I have just run this command on 8.0.4 :
> 
> SELECT 'foo' WHERE 0 NOT IN (NULL, 1);

0 <> NULL   (Indeed nothing equals NULL, other then sometimes NULL itself)

0 <> 1

Therefore, the statement: 0 NOT IN (NULL, 1)
Should always equate to false.

Therefore No rows returned.  Ever.

Terry
> 
> And it resulted is zero rows.
> Without NULL it is OK.
> Is this a bug, or the standard has such a rule?
> 
> Best Regards,
> Otto
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>               http://archives.postgresql.org
> 

-- 
Terry Fielder
terry@greatgulfhomes.com
Associate Director Software Development and Deployment
Great Gulf Homes / Ashton Woods Homes
Fax: (416) 441-9085



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: NULL in IN clause
@ 2005-10-19 20:43  David Dick <david_dick@iprimus.com.au>
  parent: =?iso-8859-2?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu>
  3 siblings, 0 replies; 5+ messages in thread

From: David Dick @ 2005-10-19 20:43 UTC (permalink / raw)
  To: Havasvölgyi Ottó <h.otto@freemail.hu>; +Cc: pgsql-sql

As i understand it, the use of NULL in SQL means the value of the column 
is unknown.  Therefore that result would seem fair.

Havasvölgyi Ottó wrote:
> Hi,
> 
> I have just run this command on 8.0.4 :
> 
> SELECT 'foo' WHERE 0 NOT IN (NULL, 1);
> 
> And it resulted is zero rows.
> Without NULL it is OK.
> Is this a bug, or the standard has such a rule?
> 
> Best Regards,
> Otto
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>               http://archives.postgresql.org
> 




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: NULL in IN clause
@ 2005-10-19 21:00  Stephan Szabo <sszabo@megazone.bigpanda.com>
  parent: =?iso-8859-2?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu>
  3 siblings, 0 replies; 5+ messages in thread

From: Stephan Szabo @ 2005-10-19 21:00 UTC (permalink / raw)
  To: Havasvölgyi Ottó <h.otto@freemail.hu>; +Cc: pgsql-sql

On Wed, 19 Oct 2005, [iso-8859-2] Havasvölgyi Ottó wrote:

> Hi,
>
> I have just run this command on 8.0.4 :
>
> SELECT 'foo' WHERE 0 NOT IN (NULL, 1);
>
> And it resulted is zero rows.
> Without NULL it is OK.
> Is this a bug, or the standard has such a rule?

This is standard behavior.

Seeing if I can do this from memory...

a NOT IN b is equivalent in the spec to NOT(a IN b). a IN b is equivalent
to a =ANY b. a =ANY b returns true if a = x is true for any x in b. a =ANY
b returns false if a = x is false for all x in b.  Otherwise it returns
unknown.

0 = NULL returns unknown
0 = 1 returns false
So, 0 IN (NULL,1) returns unknown.

NOT(unknown) is unknown.

WHERE clauses only return rows for which the search condition is true, so
a row is not returned.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: NULL in IN clause
@ 2005-10-19 21:11  Tom Lane <tgl@sss.pgh.pa.us>
  parent: =?iso-8859-2?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu>
  3 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2005-10-19 21:11 UTC (permalink / raw)
  To: Havasvölgyi Ottó <h.otto@freemail.hu>; +Cc: pgsql-sql

=?iso-8859-2?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu> writes:
> I have just run this command on 8.0.4 :

> SELECT 'foo' WHERE 0 NOT IN (NULL, 1);

> And it resulted is zero rows.
> Without NULL it is OK.
> Is this a bug, or the standard has such a rule?

This is per spec.

The computation is effectively
	NOT (0 = NULL OR 0 = 1)
	NOT (NULL OR FALSE)
	NOT NULL
	NULL
ie, the result is UNKNOWN, which WHERE treats the same as FALSE.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2005-10-19 21:11 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-19 20:17 NULL in IN clause =?iso-8859-2?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu>
2005-10-19 20:41 ` Terry Fielder <terry@ashtonwoodshomes.com>
2005-10-19 20:43 ` David Dick <david_dick@iprimus.com.au>
2005-10-19 21:00 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2005-10-19 21:11 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox