Re: Rule appears not to fire on insert w/ "except"

From: Chris Kratz <chris(dot)kratz(at)vistashare(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Rule appears not to fire on insert w/ "except"
Date: 2005-11-21 21:39:19
Message-ID: 200511211639.19240.chris.kratz@vistashare.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday 21 November 2005 03:35 pm, you wrote:
> Chris Kratz <chris(dot)kratz(at)vistashare(dot)com> writes:
> > CREATE OR REPLACE RULE debug_rule AS
> > ON INSERT TO test1
> > do INSERT INTO test_que (row_id)
> > VALUES (new.id);
>
> You would be a whole lot better off doing this with a trigger.
>
> > insert into test1
> > select id,data from test2
> > except select id,data from test1;
>
> I believe the problem with this is that the rule re-evaluates the
> command to generate the "new" results, and by that point the rows
> have already been inserted into test1, thus disappear from the
> result of the "except" ...
>
> regards, tom lane

We were afraid of that. Thanks for the info Tom. I'm not entirely sure I
grasp exactly why it's going on, but we will switch over to a trigger.

Thanks,

-Chris

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Magnus Hagander 2005-11-21 21:59:19 Re: Trouble downloading Postgres
Previous Message Jaime Casanova 2005-11-21 21:36:24 Re: Anomalies with the now() function