Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 5A59FB5FAB6 for ; Mon, 6 Jun 2011 13:41:11 -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 86640-04 for ; Mon, 6 Jun 2011 16:41:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from fetter.org (mail.fetter.org [64.81.66.25]) by mail.postgresql.org (Postfix) with ESMTP id 3CF7CB5FAAE for ; Mon, 6 Jun 2011 13:41:02 -0300 (ADT) Received: by fetter.org (Postfix, from userid 500) id 71933FBC6C5; Mon, 6 Jun 2011 09:41:01 -0700 (PDT) Date: Mon, 6 Jun 2011 09:41:01 -0700 From: David Fetter To: Tom Lane Cc: Merlin Moncure , "Jehan-Guillaume (ioguix) de Rorthais" , pgsql-bugs@postgresql.org, Marko Tiikkaja Subject: Re: BUG #6051: wCTE query fail with wrong error text on a table with rules Message-ID: <20110606164101.GA25901@fetter.org> References: <201106031542.p53FgDh5073991@wwwmaster.postgresql.org> <4184.1307222662@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4184.1307222662@sss.pgh.pa.us> User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/54 X-Sequence-Number: 30433 On Sat, Jun 04, 2011 at 05:24:22PM -0400, Tom Lane wrote: > Merlin Moncure writes: > > On Fri, Jun 3, 2011 at 10:42 AM, Jehan-Guillaume (ioguix) de Rorthais > > wrote: > >> test=# CREATE RULE test_ins AS ON INSERT TO test DO INSTEAD INSERT INTO > >> test2 VALUES (NEW.i); > >> CREATE RULE > >> test=# WITH t1 AS ( > >> DELETE FROM ONLY test RETURNING * > >> ) > >> INSERT INTO test SELECT * FROM t1; > >> ERROR: could not find CTE "t1" > > > 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). > > There are definitely cases that don't work, but I had thought we at > least threw an intelligible "not implemented" error for all of them. > This one seems to be an oversight: specifically, rewriteRuleAction() > isn't considering the possibility that the rewritten rule action will > need to make use of CTEs from the original query. > > We could paste a copy of the original's cteList into the rule action, > but there are still issues: > > * If there's more than one rule action, we could end up executing > multiple copies of the same CTE query; which breaks the expectation > of single evaluation for a CTE. > > * If there are CTEs attached to the rule action, as well as to the > original query, and there is a conflict of CTE names between them, > we can't handle that AFAICS. (The planner expects to look up entries > in a cteList by name...) > > * Maybe some other things that aren't obvious yet. > > I don't particularly mind throwing a not-implemented error for the first > case (ie, just say multiple rule actions don't mix with CTE queries); Great :) > but the second case seems seriously annoying, since there's no way > for someone to write a CTE-containing rule action without risking a > conflict. Ideas anybody? Is there some way to throw "not implemented" there, too? It seems to me that making accommodations for the user-modifiable part of our rewrite rules isn't the right direction to go, as we're well on our way to phasing the user-modifiable part out. Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate