Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 556F39FB88C for ; Mon, 14 May 2007 12:37:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 57196-02 for ; Mon, 14 May 2007 12:37:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 602A79FB2DE for ; Mon, 14 May 2007 12:37:38 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l4EFbbtg012153; Mon, 14 May 2007 11:37:37 -0400 (EDT) To: Gary Stainburn cc: pgsql-sql@postgresql.org Subject: Re: select ..... not in ..... In-reply-to: <200705141607.25712.gary.stainburn@ringways.co.uk> References: <200705141607.25712.gary.stainburn@ringways.co.uk> Comments: In-reply-to Gary Stainburn message dated "Mon, 14 May 2007 16:07:24 +0100" Date: Mon, 14 May 2007 11:37:37 -0400 Message-ID: <12152.1179157057@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/104 X-Sequence-Number: 28384 Gary Stainburn writes: > So, who does this select not return the row? > select v_d_code, v_o_number, v_vin, v_status from vista_details where v_vin > not in ( > goole(# select substring(w_vin from '(.{11}$)') from walon); NOT IN with a sub-select that returns any NULL values cannot succeed; the result is either FALSE (definite match) or NULL (because of the NULL comparison results). You could work around that with a COALESCE, but I think a less klugy and better-performing answer would be to write it as a left join: select v_d_code, v_o_number, v_vin, v_status from vista_details left join walon on (v_vin = substring(w_vin from '(.{11}$)')) where walon.some-never-null-column IS NULL; The where-clause rejects any actual join matches... regards, tom lane