Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 36D46B5F6C7 for ; Fri, 3 Jun 2011 16:57:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 74623-04 for ; Fri, 3 Jun 2011 19:57:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f174.google.com (mail-qy0-f174.google.com [209.85.216.174]) by mail.postgresql.org (Postfix) with ESMTP id A00F0B5F6A8 for ; Fri, 3 Jun 2011 16:57:00 -0300 (ADT) Received: by qyk7 with SMTP id 7so3079207qyk.19 for ; Fri, 03 Jun 2011 12:57:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=YNbrJfZFjI/4wPoxvrCwWbAyDNAblcQCgMuvL/+LJtY=; b=mwu3CEX5+wqynj3r9TQXQpW2+8nF6Vil/e36sQtkcudQuthZ/lOylzoGb7KO/36OUJ p835+wzDBruhVbNQ+/JKzUMQ2DFv0ay4R5b5P7pQG2M4DlIxpwwxZzOygk/QFhafLpUa aeAHu/gVPr6V0QZ/OQzJRkJYOzYVx+zxq7t3E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ji+FjmZJjHYOb4uvzl4yCIvvEHPqwkft4/TpOM0/JpYBJGQJWhyr+BM/3DGrKAWHRk qKsfsiabj7CSMHeqWp1k1atl3lv1jjNTRt81EMZINYgYRO7WQNEGJGT70Bol7mT4WQ5p xGZyu4iEHAdQa5OtUI1NbrhHEmM8KM1Vrm92c= MIME-Version: 1.0 Received: by 10.224.211.202 with SMTP id gp10mr84879qab.183.1307131020069; Fri, 03 Jun 2011 12:57:00 -0700 (PDT) Received: by 10.224.54.147 with HTTP; Fri, 3 Jun 2011 12:57:00 -0700 (PDT) In-Reply-To: <201106031542.p53FgDh5073991@wwwmaster.postgresql.org> References: <201106031542.p53FgDh5073991@wwwmaster.postgresql.org> Date: Fri, 3 Jun 2011 14:57:00 -0500 Message-ID: Subject: Re: BUG #6051: wCTE query fail with wrong error text on a table with rules From: Merlin Moncure To: "Jehan-Guillaume (ioguix) de Rorthais" Cc: pgsql-bugs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/43 X-Sequence-Number: 30422 On Fri, Jun 3, 2011 at 10:42 AM, Jehan-Guillaume (ioguix) de Rorthais wrote: > > The following bug has been logged online: > > Bug reference: =A0 =A0 =A06051 > Logged by: =A0 =A0 =A0 =A0 =A0Jehan-Guillaume (ioguix) de Rorthais > Email address: =A0 =A0 =A0jgdr@dalibo.com > PostgreSQL version: 9.1beta1 > Operating system: =A0 Linux x86_64 > Description: =A0 =A0 =A0 =A0wCTE query fail with wrong error text on a ta= ble with > rules > Details: > > While testing wCTE, I tried to empty a parent table, feeding its child us= ing > rules with this kind of query: > > =A0WITH t1 AS ( > =A0 =A0DELETE FROM ONLY test RETURNING * > =A0) > =A0INSERT INTO test SELECT * FROM t1; > > It works perfectly on a table without rules, but fail with what seems lik= e a > non related error message if there is a rule on INSERT on this table: > > =A0test=3D# WITH t1 AS ( > =A0 =A0DELETE FROM ONLY test RETURNING * > =A0) > =A0INSERT INTO test SELECT * FROM t1; > =A0ERROR: =A0could not find CTE "t1" > > I was expecting this query either to work or raise a comprehensive error > message. > > Here is a simple script to reproduce this behaviour: > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D> > $ createdb test > > $ psql test > psql (9.1beta1) > Type "help" for help. > > test=3D# SELECT version(); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0version > > -------------------------------------------------------------------------= --- > -------------------------------- > =A0PostgreSQL 9.1beta1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) > 4.6.0 20110513 (prerelease), 64-bit > (1 row) > > test=3D# CREATE table test AS select i from generate_series(1,3) as t(i); > SELECT 3 > test=3D# SELECT * FROM test; > =A0i > --- > =A01 > =A02 > =A03 > (3 rows) > > test=3D# WITH t1 AS ( > test(# DELETE FROM ONLY test RETURNING * > test(# ) > test-# INSERT INTO test SELECT * FROM t1; > INSERT 0 3 > test=3D# SELECT * FROM test; > =A0i > --- > =A01 > =A02 > =A03 > (3 rows) > > test=3D# CREATE TABLE test2 () inherits (test); > CREATE TABLE > test=3D# CREATE RULE test_ins AS ON INSERT TO test DO INSTEAD INSERT INTO > test2 VALUES (NEW.i); > CREATE RULE > test=3D# WITH t1 AS ( > DELETE FROM ONLY test RETURNING * > ) > INSERT INTO test SELECT * FROM t1; > ERROR: =A0could not find CTE "t1" > <=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IIRC the fact that rules don't play nice with wCTE was brought up several times during the implementation discussions. I'm not saying the error message is great, but you can pretty much add this to the giant pile of reasons not to use rules at all (particularly in 9.1 with the view triggers). merlin