Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BE1AB63272B for ; Wed, 28 Jan 2009 15:51:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 62301-02 for ; Wed, 28 Jan 2009 15:51:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id B2C3D632721 for ; Wed, 28 Jan 2009 15:50:15 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n0SJnq5w021338; Wed, 28 Jan 2009 14:49:52 -0500 (EST) To: jd@commandprompt.com cc: Scott Whitney , "'Hoover, Jeffrey'" , "'Kevin Grittner'" , pgsql-admin@postgresql.org Subject: Re: Strange query problem... In-reply-to: <1233168415.10539.2.camel@jd-laptop.pragmaticzealot.org> References: <20090128183715.A03677E4E79@mail.int.journyx.com> <1233168415.10539.2.camel@jd-laptop.pragmaticzealot.org> Comments: In-reply-to "Joshua D. Drake" message dated "Wed, 28 Jan 2009 10:46:55 -0800" Date: Wed, 28 Jan 2009 14:49:52 -0500 Message-ID: <21337.1233172192@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200901/155 X-Sequence-Number: 31202 "Joshua D. Drake" writes: > This looks like a NULL vs '' issue. Am I wrong? No, it's a NULL vs NOT IN issue. Specifically, if the subquery yields any NULLs and the comparison operator is strict (which nearly all are) then it's impossible to get a TRUE result from the NOT IN --- the only possibilities are FALSE (if a match is found among the non-nulls) or NULL (if not). Standard gotcha for newbie SQL coders. My recommendation is to use NOT EXISTS instead; it's got less surprising semantics (and, as of 8.4, it'll get optimized significantly better than NOT IN). regards, tom lane