Re: I don't understand...

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: I don't understand...
Дата
Msg-id Pine.LNX.4.30.0105221637010.757-100000@peter.localdomain
обсуждение исходный текст
Ответ на I don't understand...  ("Gabor Csuri" <gcsuri@coder.hu>)
Список 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@gmx.net   http://funkturm.homeip.net/~peter



В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Sergey E. Volkov"
Дата:
Сообщение: Re: PL/pgSQL CURSOR support
Следующее
От: "Ross J. Reedstrom"
Дата:
Сообщение: Re: Re: I don't understand...