NOT IN issue - Mailing list pgsql-general

From Marc SCHAEFER
Subject NOT IN issue
Date
Msg-id Pine.LNX.3.96.1010704173135.1958A-100000@defian.alphanet.ch
Whole thread Raw
Responses Re: NOT IN issue
List pgsql-general
Hi,

I feel like not having understood something, or maybe I should upgrade ?

simplified setup:

   CREATE TABLE personne (id SERIAL, PRIMARY KEY(id), UNIQUE(id));
   CREATE TABLE utilisateur_news (id INT4 REFERENCES personne);
   INSERT INTO personne VALUES(1);
   INSERT INTO personne VALUES(2);
   INSERT INTO personne VALUES(3);
   INSERT INTO utilisateur_news VALUES(2);

the above works without any problem with the two NOT IN and EXISTS
case.

   SELECT id
   FROM personne p
   WHERE p.id NOT IN (SELECT DISTINCT un.id
                      FROM
                      utilisateur_news un);

this is working properly:

   SELECT p.id
   FROM personne p
   WHERE NOT EXISTS (SELECT un.id
                     FROM utilisateur_news un
                     WHERE (un.id = p.id));

Now, I have a database in production that is slightly more complex but has
the same types for id, and in that database, the NOT IN FORM doesn't
return any results, but the EXISTS does.

This is with 7.1release-3.potato.1, a Debian test package.

Is my SQL code correct ? Any idea ?

Thanks.



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCH] Partial indicies almost working (I think)
Next
From: Alessio Bragadini
Date:
Subject: Re: Red Hat to support PostgreSQL