X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F20589DCA27 for ; Wed, 28 Dec 2005 11:47:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92665-02 for ; Wed, 28 Dec 2005 11:47:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id 127599DC9C9 for ; Wed, 28 Dec 2005 11:47:38 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1ErdWY-0006gY-00; Wed, 28 Dec 2005 10:47:34 -0500 To: elein Cc: Tom Lane , George Pavlov , pgsql-sql@postgresql.org Subject: Re: "large" IN/NOT IN subqueries result in query returning wrong data References: <3697.1135712691@sss.pgh.pa.us> <20051228001251.GB20674@varlena.com> <9416.1135729540@sss.pgh.pa.us> <20051228003503.GE20674@varlena.com> In-Reply-To: <20051228003503.GE20674@varlena.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 28 Dec 2005 10:47:33 -0500 Message-ID: <878xu55ilm.fsf@stark.xeocode.com> Lines: 18 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.112 required=5 tests=[AWL=0.112] X-Spam-Score: 0.112 X-Spam-Level: X-Archive-Number: 200512/219 X-Sequence-Number: 23761 elein 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