Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbMds-0002Tk-MH for pgsql-general@arkaria.postgresql.org; Mon, 04 Apr 2022 13:21:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nbMdr-0000mN-I9 for pgsql-general@arkaria.postgresql.org; Mon, 04 Apr 2022 13:21:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbMdr-0000mE-8C for pgsql-general@lists.postgresql.org; Mon, 04 Apr 2022 13:21:11 +0000 Received: from gw2.antarean.org ([141.105.125.208]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nbMdo-0006Q9-Le for pgsql-general@lists.postgresql.org; Mon, 04 Apr 2022 13:21:10 +0000 Received: from localhost (localhost [127.0.0.1]) by gw2.antarean.org (Postfix) with ESMTP id 4KXB784ZkHz8vPH for ; Mon, 4 Apr 2022 15:13:56 +0200 (CEST) X-Virus-Scanned: amavisd-new at antarean.org Received: from gw2.antarean.org ([127.0.0.1]) by localhost (gw2.antarean.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XypyaVsJ3qxu for ; Mon, 4 Apr 2022 15:13:56 +0200 (CEST) Received: from mailstore1.adm.antarean.org (localhost [127.0.0.1]) by gw2.antarean.org (Postfix) with ESMTP id 4KXB7830TPz8v7q for ; Mon, 4 Apr 2022 15:13:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailstore1.adm.antarean.org (Postfix) with ESMTP id 4KXBHR5GFMz15 for ; Mon, 4 Apr 2022 15:21:07 +0200 (CEST) X-Virus-Scanned: amavisd-new at antarean.org Received: from mailstore1.adm.antarean.org ([127.0.0.1]) by localhost (mailstore1.adm.antarean.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4DqODGCQjB3z for ; Mon, 4 Apr 2022 15:21:07 +0200 (CEST) Received: from iris.localnet (iris.adm.antarean.org [10.55.16.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mailstore1.adm.antarean.org (Postfix) with ESMTPSA id 4KXBHR45VRz13 for ; Mon, 4 Apr 2022 15:21:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=antarean.org; s=default; t=1649078467; bh=Q0KR8DGcs9LUa59SR6/xNzBJQx+gVrYEmACxncoVc+o=; h=From:To:Subject:Date:In-Reply-To:References; b=cLQJQiOXZMIHzF9X486Y9Ru5b4ezqO4h0ecYkG8Fp8nswVAOWeC32+i+oydmA7guU 44tCtrOcYcWFL3Yg3hxVk23cHqPTj5ynkYg01TgxhswckWAuLzi7W7Fz3fELv5HDs7 vB+ilWnnVqRqrALO4I3fZx92Q9kuTjNmgLH/aqE0= From: "J. Roeleveld" 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> In-Reply-To: References: <5820573.lOV4Wx5bFT@iris> <2ddba2d73d0d54da3396ff2dad9e7d2d@vivaldi.net> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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