PostgreSQL 7.4 Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Chapter 35. Triggers | Fast Forward | Next |
If you execute SQL commands in your trigger function, and these commands access the table that the trigger is for, then you need to be aware of the data visibility rules, because they determine whether these SQL commands will see the data change that the trigger is fired for. Briefly:
The data change (insertion, update, or deletion) causing the trigger to fire is naturally not visible to SQL commands executed in a before trigger, because it hasn't happened yet.
However, SQL commands executed in a before trigger will see the effects of data changes for rows previously processed in the same outer command. This requires caution, since the ordering of these change events is not in general predictable; a SQL command that affects multiple rows may visit the rows in any order.
When an after trigger is fired, all data changes made by the outer command are already complete, and are visible to executed SQL commands.
Further information about data visibility rules can be found in Section 41.4. The example in Section 35.4 contains a demonstration of these rules.