X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 746F352B6F for ; Fri, 15 Jul 2005 11:10:51 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52421-05 for ; Fri, 15 Jul 2005 14:10:41 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 8B85952A80 for ; Fri, 15 Jul 2005 11:10:36 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j6FEAbE0009026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Jul 2005 08:10:40 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j6FEAbpc030495; Fri, 15 Jul 2005 08:10:37 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j6FEAbTq030494; Fri, 15 Jul 2005 08:10:37 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 15 Jul 2005 08:10:37 -0600 From: Michael Fuhr To: Tom Lane Cc: Luca Pireddu , pgsql-sql@postgresql.org Subject: Re: problem (bug?) with "in (subquery)" Message-ID: <20050715141037.GA30461@winnie.fuhr.org> References: <200507140134.21133.luca@cs.ualberta.ca> <10971.1121435967@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <10971.1121435967@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.109 tagged_above=0 required=5 tests=AWL, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200507/142 X-Sequence-Number: 22120 On Fri, Jul 15, 2005 at 09:59:27AM -0400, Tom Lane wrote: > Luca Pireddu 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/