Reputation: 11
I have to write a statement level trigger, in which I need to know how about a column if the values is changed within 24 hour. For example my table has these three column Col_1|Col2|Col3, I want to know if an update action has caused any changed in col_1 and want to store that value in a separate table. I don't want to use row level triggers as an update can cause changes to many rows in my table. I know in oracle we can use compound triggers and achieve the same thing with statement level trigger. But any suggestions for postgres users.
Thanks a lot!!
Upvotes: 1
Views: 365
Reputation: 78581
On a row-level trigger, you can know, and in fact check for it before the trigger is event fired:
create trigger foo after update on foo
for each row
when (row(old.col1, old.col2, …) is distinct from row(new.col1, new.col2, …))
execute procedure foo_upd();
Statement-level triggers offer no such possibility, since they're fired on any relevant statement on the table.
However, in the odd and unusual cases where it's actually needed, you've two options:
Upvotes: 1