Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A2CDF2E00AB for ; Sun, 16 Mar 2008 14:55:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 49703-01 for ; Sun, 16 Mar 2008 14:54:58 -0300 (ADT) X-Greylist: delayed 00:07:10.742774 by SQLgrey-1.7.5 Received: from ls405.t-com.hr (ls405.t-com.hr [195.29.150.135]) by postgresql.org (Postfix) with ESMTP id 9EAA12E00A1 for ; Sun, 16 Mar 2008 14:54:57 -0300 (ADT) Received: from ls242.t-com.hr (ls242.t-com.hr [195.29.150.134]) by ls405.t-com.hr (Postfix) with ESMTP id C310F474EA for ; Sun, 16 Mar 2008 18:47:43 +0100 (CET) Received: from ls242.t-com.hr (localhost.localdomain [127.0.0.1]) by ls242.t-com.hr (Qmlai) with ESMTP id BFE53B08380 for ; Sun, 16 Mar 2008 18:47:43 +0100 (CET) X-Envelope-Sender: mario.splivalo@megafon.hr Received: from [192.168.10.1] (89-172-13-232.adsl.net.t-com.hr [89.172.13.232])by ls242.t-com.hr (Qmali) with ESMTP id 6D01B5BC218for ; Sun, 16 Mar 2008 18:47:39 +0100 (CET) Message-ID: <47DD5D3A.6060100@megafon.hr> Date: Sun, 16 Mar 2008 18:47:38 +0100 From: Mario Splivalo User-Agent: Thunderbird 2.0.0.12 (X11/20080227) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Subselect strange behaviour - bug? Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-imss-version: 2.050 X-imss-result: Passed X-imss-scanInfo: M:P L:N SM:0 X-imss-tmaseResult: TT:0 TS:0.0000 TC:00 TRN:0 TV:5.0.1023(15792.000) X-imss-scores: Clean:20.83813 C:2 M:3 S:5 R:5 X-imss-settings: Baseline:1 C:1 M:1 S:1 R:1 (0.0000 0.0000) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200803/90 X-Sequence-Number: 30418 I have two tables, 'configured' like this: melem=# \d t1 Table "public.t1" Column | Type | Modifiers --------+-------------------+----------- id | integer | value | character varying | melem=# \d t2 Table "public.t2" Column | Type | Modifiers --------+-------------------+----------- id1 | integer | value | character varying | And here is the data from both tables: melem=# select * from t1; id | value ----+------- 1 | 1 2 | 2 3 | 3 (3 rows) melem=# select * from t2; id1 | value -----+------- 1 | 1 2 | 2 3 | 3 4 | 4 (4 rows) And here is the 'problematic' query: melem=# select * from t2 where id1 in (select id1 from t1); id1 | value -----+------- 1 | 1 2 | 2 3 | 3 4 | 4 (4 rows) I guess postgres should tell me that column name id1 is nonexistant in table t1. Now, if I change subselect to select correct column name, everything is ok: melem=# select * from t2 where id1 in (select id from t1); id1 | value -----+------- 1 | 1 2 | 2 3 | 3 (3 rows) I have found out that this 'error' pops up only if the columns in both subselect query and the 'super'select query are the same. For instance: melem=# select * from t2 where id1 in (select id2 from t1); ERROR: column "id2" does not exist LINE 1: select * from t2 where id1 in (select id2 from t1); ^ melem=# I have tested this on postgres 8.3.0, 8.2.6 and 8.2.4, and the results are the same. I donwloaded the sources for three mentioned versions of postgres, and built it on Linux 2.6.22-14 (Ubuntu 7.10) using gcc 4.1.3, as well as on Debian stable (Linux 2.6.22.1 with gcc 4.1.2). Mario