John Hansen wrote:
> Right, except:
> create table test (a text, b int); create or replace rule test_rule
> as on insert to test where exists(select 1 from test where a = NEW.a)
> do instead select * from test;
> insert into test (a,b) VALUES ('first',2); a | b -------+--- first
> | 2 (1 row)
> select * from test; a | b -------+--- first | 2 (1 row)
> Now, the select on the first insert should NOT have happened.....
> Since this is a do instead rule. The insert should of course happen,
> since it's not present in the table.
> Or am I missing the point completely?
You are, but it's not your fault. You're still thinking of it as a
sequence of instructions, try thinking of it as a single expression that
To quote from the (v8.0) docs (ch 32 - The Rule System), for your case:
"Qualification given and INSTEAD
the query tree from the rule action with the rule qualification and
the original query tree's qualification; and the original query tree
with the negated rule qualification added"
So, in your case you get two branches:
1. INSERT ... WHERE NOT EXISTS (...)
2. SELECT * FROM TEST WHERE EXISTS (...)
Is this making sense?
In response to
pgsql-bugs by date
|Next:||From: Sokolov Yura||Date: 2005-01-12 14:47:51|
|Subject: BUG #1391: Perl trusted language triggers can't properly access $_SHARED|
|Previous:||From: Pailloncy Jean-Gerard||Date: 2005-01-12 13:34:21|
|Subject: 8rc5 on OpenBSD|