Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D12CBB5DC60 for ; Fri, 16 Sep 2011 06:59:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 58521-06 for ; Fri, 16 Sep 2011 09:59:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 2483EB5DC5E for ; Fri, 16 Sep 2011 06:59:11 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p8G9xBE1036901 for ; Fri, 16 Sep 2011 09:59:11 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p8G9xBDu036900; Fri, 16 Sep 2011 09:59:11 GMT (envelope-from www) Date: Fri, 16 Sep 2011 09:59:11 GMT Message-Id: <201109160959.p8G9xBDu036900@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6209: Invalid subquery is accepted within a IN() clause From: "Marc Mamin" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201109/94 X-Sequence-Number: 31111 The following bug has been logged online: Bug reference: 6209 Logged by: Marc Mamin Email address: marc@intershop.de PostgreSQL version: 9.1beta3 Operating system: Linux Description: Invalid subquery is accepted within a IN() clause Details: Hello, This is somehow similar to BUG #6154 but I don't have yet a 9.1. Version to test and I'm not sure that 9.1 already contains the Fix. This issue can also be reproduced in 8.3.13 HTH, Marc Mamin steps to repeat: CREATE TABLE test_f_files_steps ( id bigserial NOT NULL, file_id integer NOT NULL, class_id integer NOT NULL, step_id integer NOT NULL, "timestamp" bigint NOT NULL, infotext character varying, efm_uid integer, CONSTRAINT test_f_files_steps_pk PRIMARY KEY (id) ); CREATE TABLE test_f_files_status ( id serial NOT NULL, class_id integer NOT NULL, file_name character varying NOT NULL, last_step_id integer NOT NULL, runs smallint, size bigint, "timestamp" bigint, plainday integer, success boolean, linecount integer, rejected integer, efm_uid integer NOT NULL, CONSTRAINT test_f_files_status_pk PRIMARY KEY (id, class_id) ); This is not valid, but is accepted. EXPLAIN analyze select * from test_f_files_steps where id in (select id from ( select file_id,class_id from test_f_files_steps EXCEPT select id,class_id from test_f_files_status )foo ) Seq Scan on test_f_files_steps (cost=0.00..26895.75 rows=430 width=64) (actual time=0.001..0.001 rows=0 loops=1) Filter: (SubPlan 1) SubPlan 1 -> Subquery Scan on foo (cost=0.00..62.00 rows=200 width=0) (never executed) -> HashSetOp Except (cost=0.00..60.00 rows=200 width=8) (never executed) -> Append (cost=0.00..52.00 rows=1600 width=8) (never executed) -> Subquery Scan on "*SELECT* 1" (cost=0.00..27.20 rows=860 width=8) (never executed) -> Seq Scan on test_f_files_steps (cost=0.00..18.60 rows=860 width=8) (never executed) -> Subquery Scan on "*SELECT* 2" (cost=0.00..24.80 rows=740 width=8) (never executed) -> Seq Scan on test_f_files_status (cost=0.00..17.40 rows=740 width=8) (never executed) Total runtime: 0.087 ms calling the IN subquery is correctly rejected: select id from ( select file_id,class_id from test_f_files_steps EXCEPT select id,class_id from test_f_files_status )foo ERROR: column "id" does not exist drop table test_f_files_steps; drop table test_f_files_status;