NULLS and <> : Discrepancies ?

From: "Emmanuel Charpentier,,," <charpent(at)bacbuc(dot)dyndns(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: NULLS and <> : Discrepancies ?
Date: 2000-12-24 07:57:24
Message-ID: 3A45AC64.1000302@bacbuc.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Sorry for intruding, but the following question did not get much
attention on the "General" list. However, I still need the answer ...

</LurkingMode>

<NewbieMode>

Could some kind soul explain this to me ?

test1=# select distinct "Cle" from "Utilisateurs";
Cle
-----
1
2
3
4
(4 rows)

test1=# select distinct "CleUtil" from "Histoires";
CleUtil
---------
1

(2 rows) -- Uuhhh !

test1=# select count(*) as NbRec from "Histoires" where "CleUtil" is null;
nbrec
-------
2
(1 row) -- Ah Ahh ... I have NULLs.

test1=# select distinct "Cle" from "Utilisateurs" where "Cle" in
test1-# (select distinct "CleUtil" from "Histoires");
Cle
-----
1
(1 row) -- That's OK ...

test1=# select distinct "Cle" from "Utilisateurs" where "Cle" not in
test1-# (select distinct "CleUtil" from "Histoires");
Cle
-----
(0 rows) -- That's definitively *NOT* OK ! However

test1=# select distinct "Cle" from "Utilisateurs" where "Cle" not in
test1-# (select distinct "CleUtil" from "Histoires" where "CleUtil" is
not null);
Cle
-----
2
3
4
(3 rows) -- That's what I expected in the first place.

Could someone explain to me why not eliminating nulls destroys the
potential results of the query ? In other words, for any X not null, X
not in (some NULLs) is false.

</NewbieMode>

<LurkingMode>

Emmanuel Charpentier

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Oliver Elphick 2000-12-24 13:23:43 Re: RI problem with inherited table (fwd)
Previous Message Tom Lane 2000-12-24 06:19:34 Re: 7.1 on DEC/Alpha