pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: select ..... not in .....
Date: Mon, 14 May 2007 11:37:37 -0400
Message-ID: <12152.1179157057@sss.pgh.pa.us> (raw)
In-Reply-To: <200705141607.25712.gary.stainburn@ringways.co.uk>
References: <200705141607.25712.gary.stainburn@ringways.co.uk>

Gary Stainburn <gary.stainburn@ringways.co.uk> 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



view thread (2+ messages)

Message-ID: <12152.1179157057@sss.pgh.pa.us>
Permalink:  ../12152.1179157057@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12152.1179157057@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, gary.stainburn@ringways.co.uk
  Subject: Re: select ..... not in .....
  In-Reply-To: <12152.1179157057@sss.pgh.pa.us>

* 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