Re: problem (bug?) with "in (subquery)" - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: problem (bug?) with "in (subquery)"
Date
Msg-id 20050715141037.GA30461@winnie.fuhr.org
Whole thread Raw
In response to Re: problem (bug?) with "in (subquery)"  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: problem (bug?) with "in (subquery)"
List pgsql-sql
On Fri, Jul 15, 2005 at 09:59:27AM -0400, Tom Lane wrote:
> Luca Pireddu <luca@cs.ualberta.ca> writes:
> > So, am I wrong in expecting each strain record to appear only once in the 
> > result set?  Or is there something wrong with PostgreSQL?
> 
> Could we see a self-contained example (table definitions and sample data
> as a SQL script)?  I don't really have time to reverse-engineer a test
> case from your description ...

I've been reverse-engineering and simplifying this.  Here's something
that I think is close:

CREATE TABLE foo (id integer);
CREATE TABLE bar (id1 integer, id2 integer);

INSERT INTO foo VALUES (1);

INSERT INTO bar VALUES (1, 1);
INSERT INTO bar VALUES (2, 2);
INSERT INTO bar VALUES (3, 1);

SELECT *
FROM foo
WHERE id IN (SELECT id2 FROM (SELECT DISTINCT id1, id2 FROM bar) AS s);id 
---- 1 1
(2 rows)

SELECT *
FROM foo
WHERE id IN (SELECT id2 FROM (SELECT id1, id2 FROM bar) AS s);id 
---- 1
(1 row)

8.0.3 and HEAD behave as shown.  7.4.8, 7.3.10, and 7.2.8 return a
single row for both queries.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: problem (bug?) with "in (subquery)"
Next
From: "Dinesh Pandey"
Date:
Subject: Postgres for Fedora Core 2 OS ****************