pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: George Pavlov <gpavlov@mynewplace.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: "large" IN/NOT IN subqueries result in query returning wrong data
Date: Tue, 27 Dec 2005 14:44:51 -0500
Message-ID: <3697.1135712691@sss.pgh.pa.us> (raw)
In-Reply-To: <CCB89282FCE1024EA3DCE687A96A5164039EBD13@ehost010-6.exch010.intermedia.net>
References: <CCB89282FCE1024EA3DCE687A96A5164039EBD13@ehost010-6.exch010.intermedia.net>

"George Pavlov" <gpavlov@mynewplace.com> 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



view thread (8+ messages)  latest in thread

Message-ID: <3697.1135712691@sss.pgh.pa.us>
Permalink:  ../3697.1135712691@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3697.1135712691@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, gpavlov@mynewplace.com
  Subject: Re: "large" IN/NOT IN subqueries result in query returning wrong data
  In-Reply-To: <3697.1135712691@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