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 3B4869DC81A for ; Tue, 27 Dec 2005 15:44:57 -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 76905-07 for ; Tue, 27 Dec 2005 15:44:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 6CE809DC80C for ; Tue, 27 Dec 2005 15:44:51 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBRJipbD003698; Tue, 27 Dec 2005 14:44:51 -0500 (EST) To: "George Pavlov" cc: pgsql-sql@postgresql.org Subject: Re: "large" IN/NOT IN subqueries result in query returning wrong data In-reply-to: References: Comments: In-reply-to "George Pavlov" message dated "Tue, 27 Dec 2005 11:41:33 -0800" Date: Tue, 27 Dec 2005 14:44:51 -0500 Message-ID: <3697.1135712691@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.049 required=5 tests=[AWL=0.049] X-Spam-Score: 0.049 X-Spam-Level: X-Archive-Number: 200512/211 X-Sequence-Number: 23753 "George Pavlov" writes: > select count(*) from t2 where t2.name not in ( > select t1.name from t1 limit 261683) > --> 13 > select count(*) from t2 where t2.name not in ( > select t1.name from t1 limit 261684) > --> 0 > What is so magical about 261683? Most likely, the 261684'th row of t1 has a NULL value of name. Many people find the behavior of NOT IN with nulls unintuitive, but it's per SQL spec ... regards, tom lane