Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a trigger function supposed to trigger another trigger?

Tags:

postgresql

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?

like image 213
Werner Karl Avatar asked Dec 06 '25 16:12

Werner Karl


1 Answers

You are correct, trigger_function_bwill 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 the UPDATE command's SET 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 by BEFORE UPDATE triggers are not considered. Conversely, a command such as UPDATE ... SET x = x ... will fire a trigger on column x, 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.

like image 177
Laurenz Albe Avatar answered Dec 11 '25 06:12

Laurenz Albe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!