pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: elein <elein@varlena.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: George Pavlov <gpavlov@mynewplace.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: "large" IN/NOT IN subqueries result in query returning wrong data
Date: 28 Dec 2005 10:47:33 -0500
Message-ID: <878xu55ilm.fsf@stark.xeocode.com> (raw)
In-Reply-To: <20051228003503.GE20674@varlena.com>
References: <CCB89282FCE1024EA3DCE687A96A5164039EBD13@ehost010-6.exch010.intermedia.net>
	<3697.1135712691@sss.pgh.pa.us>
	<20051228001251.GB20674@varlena.com>
	<9416.1135729540@sss.pgh.pa.us>
	<20051228003503.GE20674@varlena.com>

elein <elein@varlena.com> writes:

> > Note that the above are not inverses because you changed the lefthand
> > input.  You do get consistent results when you just add or omit NOT:
> Yes, you are right. I skipped the permutations to get down to the point.

Remember that NULL means "unknown". So "1 IN (1,2,NULL)" *should* be true
because regardless of what that unknown value is it's still obvious that 1
really is in the list. And "3 NOT IN (1,2,NULL)" is unknown because it depends
on whether that unknown quantity is 3 or not.

IN is the same as "= ANY" so "1 IN (1,2,NULL)" is the same as 
"1=1 OR 1=2 OR 1=NULL" which is true even though the last of the three is null.



-- 
greg




view thread (8+ messages)

Message-ID: <878xu55ilm.fsf@stark.xeocode.com>
Permalink:  ../878xu55ilm.fsf@stark.xeocode.com/
Also on:    postgresql.org/message-id/878xu55ilm.fsf@stark.xeocode.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gsstark@mit.edu, elein@varlena.com, tgl@sss.pgh.pa.us, gpavlov@mynewplace.com
  Subject: Re: "large" IN/NOT IN subqueries result in query returning wrong data
  In-Reply-To: <878xu55ilm.fsf@stark.xeocode.com>

* 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