Re: I don't understand...

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Gabor Csuri <gcsuri(at)coder(dot)hu>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: I don't understand...
Date: 2001-05-22 14:40:55
Message-ID: Pine.LNX.4.30.0105221637010.757-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Gabor Csuri writes:

> SELECT DISTINCT h_name
> >FROM haszon
> WHERE h_name NOT IN (SELECT cn_name FROM carname)
>
> +--------+
> | h_name |
> +--------+
> +--------+
> Query OK, 0 rows in set (0,10 sec)
>
> Why ?

Because one of the cn_name values is NULL. Observe the semantics of the
IN operator if the set contains a NULL value:

h_name NOT IN (a, b, c)
NOT (h_name = a OR h_name = b OR h_name = c)

Say c is null:

NOT (h_name = a OR h_name = b OR h_name = NULL)
NOT (h_name = a OR h_name = b OR NULL)
NOT (NULL)
NULL

which is false.

You might want to add a ... WHERE cn_name IS NOT NULL in the subquery.

--
Peter Eisentraut peter_e(at)gmx(dot)net http://funkturm.homeip.net/~peter

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ross J. Reedstrom 2001-05-22 14:43:40 Re: Re: I don't understand...
Previous Message Bruce Momjian 2001-05-22 14:08:01 Open Office