From: J. Roeleveld <joost@antarean.org>
To: pgsql-general@lists.postgresql.org
Subject: Re: Select .... where id not in (....) returns 0 incorrectly
Date: Mon, 04 Apr 2022 15:21:07 +0200
Message-ID: <2245474.ElGaqSPkdT@iris> (raw)
In-Reply-To: <CAM8SmLWx8b4kZN64wR2iYtQEKuSmYEXS7E42c+D5OPxdyWx9iQ@mail.gmail.com>
References: <5820573.lOV4Wx5bFT@iris>
<2ddba2d73d0d54da3396ff2dad9e7d2d@vivaldi.net>
<CAM8SmLWx8b4kZN64wR2iYtQEKuSmYEXS7E42c+D5OPxdyWx9iQ@mail.gmail.com>
On Monday, April 4, 2022 2:50:44 PM CEST Jeremy Smith wrote:
> > Doesn't this usually happen if q.id contains NULL. That is as per ANSI
> > standard.
>
> Yes, there's a good description of this here:
> https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_NOT_IN
>
> It would be better to use NOT EXISTS:
> select count(*) from snapshotlist where NOT EXISTS (SELECT FROM q WHERE q.id
> = snapshotlist.id);
>
>
> -Jeremy
Thank you Jeremy and Ravi.
This was actually the case, I forgot there is 1 NULL-value in that list.
Personally, I think NULL should be treated as a seperate value and not lead to
strange behaviour.
I will need to look into my queries and get rid of "NOT IN" constructions when
the list comes from a different query.
--
Joost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: joost@antarean.org
Subject: Re: Select .... where id not in (....) returns 0 incorrectly
In-Reply-To: <2245474.ElGaqSPkdT@iris>
References: <5820573.lOV4Wx5bFT@iris> <2ddba2d73d0d54da3396ff2dad9e7d2d@vivaldi.net> <CAM8SmLWx8b4kZN64wR2iYtQEKuSmYEXS7E42c+D5OPxdyWx9iQ@mail.gmail.com> <2245474.ElGaqSPkdT@iris>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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