How to specify trigger execution order under PostgreSQL?
I couldn't say it better than the manual does here:
If any
BEFORE
orINSTEAD OF
trigger returnsNULL
, the operation is abandoned for that row and subsequent triggers are not fired (for that row).
Neither the (alphabetically) later triggers on the same event nor any AFTER
triggers will fire, if the BEFORE
trigger cancels.
PostgreSQL executes the triggers in alphabetical order by name. So make sure to use names that get them in the order you want. From the docs
SQL specifies that multiple triggers should be fired in time-of-creation order. PostgreSQL uses name order, which was judged to be more convenient.
BTW your SQL creates the same trigger twice.