I have a view and update rule on it, which updates another table. Now I would like to call a function, after update of
thetable is done. Also the function must be called in the same transaction as update. I tried to define an additional
updaterule on the view, but doing a SELECT in update rule spoils the affected records count:
hekotek=# create table a(id integer);
CREATE TABLE
hekotek=# create view v as select * from a;
CREATE VIEW
hekotek=# create rule r as on update to v do instead update a set id = new.id where id = old.id;
CREATE RULE
hekotek=# create rule r1 as on update to v do select 1;
CREATE RULE
hekotek=# insert into a values (1);
INSERT 1194985 1
hekotek=# update v set id = 2;?column?
---------- 1
(1 row)
hekotek=# drop rule r1 on v;
DROP RULE
hekotek=# update v set id = 3;
UPDATE 1
It's important to me to have correct affected records count returned. I cannot use triggers, because views can't have
triggers.I also cannot define the trigger on the table, because the function must be called only when updated through
theview. I think I could define the rule to call the function in update query for some dummy table: update dummy set
field= function(parameters). But is there a better way?
Tambet