Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 7A4891FE8DB for ; Wed, 25 Jan 2012 19:48:15 -0400 (AST) Received: from smtp.01.com ([199.36.142.181]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RqCZP-0001Xy-UT for pgsql-bugs@postgresql.org; Wed, 25 Jan 2012 23:48:15 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 310F03F4651 for ; Wed, 25 Jan 2012 17:47:51 -0600 (CST) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z6jjABGjciQR for ; Wed, 25 Jan 2012 17:47:51 -0600 (CST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 14B193F4C22 for ; Wed, 25 Jan 2012 17:47:51 -0600 (CST) Received: from Sidney-Stratton.local (70-36-143-92.dsl.dynamic.sonic.net [70.36.143.92]) by smtp-out-1.01.com (Postfix) with ESMTPSA id B05BE3F4651 for ; Wed, 25 Jan 2012 17:47:50 -0600 (CST) Message-ID: <4F2094A6.5090505@agliodbs.com> Date: Wed, 25 Jan 2012 15:47:50 -0800 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.24) Gecko/20111103 Lightning/1.0b2 Thunderbird/3.1.16 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: wCTE cannot be used to update parent inheritance table X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/170 X-Sequence-Number: 32237 SEVERITY: normal TYPE: SQL feature VERSION TESTED: 9.1.2 PLATFORM: Ubuntu Linux, installed from apt-get REPRODUCEABLE: 100% SUMMARY: if you attempt to UPDATE or DELETE FROM a parent table in an inheritance relationship using a wCTE, you get the following error message: ERROR: could not find plan for CTE This does not happen with INSERTs, child tables or UPDATE ONLY. STEPS TO REPRODUCE: create table parent ( id int, val text ); create table child1 ( constraint child1_part check ( id between 1 and 5 ) ) inherits ( parent ); create table child2 ( constraint child2_part check ( id between 6 and 10 ) ) inherits ( parent ); create table other_table ( whichtab text, totals int ); postgres=# insert into child1 values ( 1, 'one' ),( 2, 'two' ); INSERT 0 2 postgres=# insert into child2 values ( 6, 'six' ),( 7, 'seven' ); INSERT 0 2 postgres=# with wcte as ( select sum(id) as totalid from parent ) insert into other_table select 'parent', totalid from wcte; INSERT 0 1 postgres=# with wcte as ( select sum(id) as totalid from child1 ) insert into other_table select 'parent', totalid from wcte; INSERT 0 1 postgres=# with wcte as ( select whichtab from other_table ) update child1 set val = whichtab from other_table; UPDATE 2 postgres=# with wcte as ( select whichtab from other_table ) update parent set val = whichtab from other_table; UPDATE 4 postgres=# with wcte as ( select whichtab from other_table ) update child1 set val = whichtab from wcte; UPDATE 2 postgres=# with wcte as ( select whichtab from other_table ) update parent set val = whichtab from wcte; ERROR: could not find plan for CTE "wcte" postgres=# with wcte as ( select whichtab from other_table ) update only parent set val = whichtab from wcte; UPDATE 0 postgres=# update parent set val = 'parent'; UPDATE 4 postgres=# with wcte as ( select whichtab from other_table ) insert into parent select 11, whichtab from other_table; INSERT 0 2 postgres=# with wcte as ( select whichtab from other_table ) delete from parent using wcte where val = whichtab; ERROR: could not find plan for CTE "wcte" -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com