pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: Jehan-Guillaume (ioguix) de Rorthais <jgdr@dalibo.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6051: wCTE query fail with wrong error text on a table with rules
Date: Fri, 3 Jun 2011 14:57:00 -0500
Message-ID: <BANLkTim4L2q_4DC4xc1J5YuEprbBFfZ3mg@mail.gmail.com> (raw)
In-Reply-To: <201106031542.p53FgDh5073991@wwwmaster.postgresql.org>
References: <201106031542.p53FgDh5073991@wwwmaster.postgresql.org>

On Fri, Jun 3, 2011 at 10:42 AM, Jehan-Guillaume (ioguix) de Rorthais
<jgdr@dalibo.com> wrote:
>
> The following bug has been logged online:
>
> Bug reference:      6051
> Logged by:          Jehan-Guillaume (ioguix) de Rorthais
> Email address:      jgdr@dalibo.com
> PostgreSQL version: 9.1beta1
> Operating system:   Linux x86_64
> Description:        wCTE query fail with wrong error text on a table with
> rules
> Details:
>
> While testing wCTE, I tried to empty a parent table, feeding its child using
> rules with this kind of query:
>
>  WITH t1 AS (
>    DELETE FROM ONLY test RETURNING *
>  )
>  INSERT INTO test SELECT * FROM t1;
>
> It works perfectly on a table without rules, but fail with what seems like a
> non related error message if there is a rule on INSERT on this table:
>
>  test=# WITH t1 AS (
>    DELETE FROM ONLY test RETURNING *
>  )
>  INSERT INTO test SELECT * FROM t1;
>  ERROR:  could 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:
>
> ======================>
> $ createdb test
>
> $ psql test
> psql (9.1beta1)
> Type "help" for help.
>
> test=# SELECT version();
>                                                  version
>
> ----------------------------------------------------------------------------
> --------------------------------
>  PostgreSQL 9.1beta1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC)
> 4.6.0 20110513 (prerelease), 64-bit
> (1 row)
>
> test=# CREATE table test AS select i from generate_series(1,3) as t(i);
> SELECT 3
> test=# SELECT * FROM test;
>  i
> ---
>  1
>  2
>  3
> (3 rows)
>
> test=# WITH t1 AS (
> test(# DELETE FROM ONLY test RETURNING *
> test(# )
> test-# INSERT INTO test SELECT * FROM t1;
> INSERT 0 3
> test=# SELECT * FROM test;
>  i
> ---
>  1
>  2
>  3
> (3 rows)
>
> test=# CREATE TABLE test2 () inherits (test);
> CREATE TABLE
> 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).

merlin



view thread (5+ messages)  latest in thread

Message-ID: <BANLkTim4L2q_4DC4xc1J5YuEprbBFfZ3mg@mail.gmail.com>
Permalink:  ../BANLkTim4L2q_4DC4xc1J5YuEprbBFfZ3mg@mail.gmail.com/
Also on:    postgresql.org/message-id/BANLkTim4L2q_4DC4xc1J5YuEprbBFfZ3mg@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: mmoncure@gmail.com, jgdr@dalibo.com
  Subject: Re: BUG #6051: wCTE query fail with wrong error text on a table with rules
  In-Reply-To: <BANLkTim4L2q_4DC4xc1J5YuEprbBFfZ3mg@mail.gmail.com>
  References: <201106031542.p53FgDh5073991@wwwmaster.postgresql.org> <BANLkTim4L2q_4DC4xc1J5YuEprbBFfZ3mg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox