Re: insert rule not firing on insert with exists subselect

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chris Kratz <chris(dot)kratz(at)vistashare(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: insert rule not firing on insert with exists subselect
Date: 2004-04-13 20:40:29
Message-ID: 26350.1081888829@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Chris Kratz <chris(dot)kratz(at)vistashare(dot)com> writes:
> create rule mycopyrule as on insert to table2 do insert into table3 (col1)
> values (new.col1);

> insert into table2 (col1) select col1 from table1 where not exists (select 1
> from table2 where table2.col1 = table1.col1); -- doesn't work

The rule-generated query executes after the original INSERT, and can see
its results. So by the time the rule fires, there *is* an entry in
table2 matching the table1 value, and of course the EXISTS condition
fails.

Rules are not triggers and make poor substitutes for them. You're going
to need to use a trigger for this...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2004-04-13 20:51:00 Re: Join works in 7.3.6, fails in 7.4.2
Previous Message Clodoaldo Pinto Neto 2004-04-13 20:24:49 Re: COPY TO order