is it a bug in rule system?

From: laser <laserlist(at)pgsqldb(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: is it a bug in rule system?
Date: 2008-05-28 07:56:22
Message-ID: 483D1026.2010403@pgsqldb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi all,

see query below:

create table ruleTest(id integer, name text);

create or replace rule ruleTest_insert_rule AS on insert to ruleTest
where exists(select 1 from ruleTest where ruleTest.name = NEW.name)
do instead (update ruleTest set id = id+1 where ruleTest.name = NEW.name);

create unique index ruletest_name_uniq_idx on ruletest using btree (name);

laser=# insert into ruletest(id,name) values(1, 'laser0');
INSERT 0 1
laser=# select * from ruletest;
id | name
----+--------
2 | laser0

I think the id should be 1, cause the rule condition should only affect
exist row,
but ISTM the rule act like a DO ALSO rule: insert the row first, then
update it.

any hints?

thanks and best regards

-laser

Responses

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2008-05-28 08:28:25 Re: is it a bug in rule system?
Previous Message Volkan =?utf-8?B?WWF6xLFjxLE=?= 2008-05-28 05:58:51 Re: Permission Problem for DELETE