Re: "large" IN/NOT IN subqueries result in query returning wrong data

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: "large" IN/NOT IN subqueries result in query returning wrong data
Date: 2005-12-27 19:44:51
Message-ID: 3697.1135712691@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"George Pavlov" <gpavlov(at)mynewplace(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message John McCawley 2005-12-27 19:53:30 Re: "large" IN/NOT IN subqueries result in query returning
Previous Message George Pavlov 2005-12-27 19:41:33 "large" IN/NOT IN subqueries result in query returning wrong data