Reputation: 31
I have a trigger_function_a that is triggered before insert or update of field_1 or field_2. I have another trigger_function_b that is triggered before insert or update of field_3 or field_4:
before insert or update of field_1 or field_2 => trigger_function_a
before insert or update of field_3 or field_4 => trigger_function_b
Now, trigger_function_a modifies field_3. Is trigger_function_b supposed to be triggered? I have tried it, but it is not triggered. Why? I have searched all available docs, but I have not found an answer to this.
Please don't care for syntax here. The trigger functions do work for themselves if I modify the fields by myself, e. g. via SQL. All I'm asking here is: Is a trigger function supposed to be fired if another trigger function modifies its fields?
Upvotes: 3
Views: 1204
Reputation: 246523
You are correct, trigger_function_b
will not be called in this case.
Look at the documentation:
A column-specific trigger (one defined using the
UPDATE OF column_name
syntax) will fire when any of its columns are listed as targets in theUPDATE
command'sSET
list. It is possible for a column's value to change even when the trigger is not fired, because changes made to the row's contents byBEFORE UPDATE
triggers are not considered. Conversely, a command such asUPDATE ... SET x = x ...
will fire a trigger on columnx
, even though the column's value did not change.
The key point here is that a trigger fires if and only if the column appears in the SET
list.
Upvotes: 2