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