Sometimes, your trigger functions might run into the Multiversion Concurrency Control (MVCC) visibility rules of how PostgreSQL's system interacts with changes to data.
A function declared as STABLE
or IMMUTABLE
will never see changes applied to the underlying table by the previous triggers.
A VOLATILE
function follows more complex rules which are, in a nutshell, as follows:
The statement-level
BEFORE
triggers detects whether no changes are made by the current statement, and the statement-levelAFTER
triggers detects all of the changes made by the statement.Data changes by the operation to the row causing the trigger to fire are, of course, not visible to the
BEFORE
triggers, as the operation has not occurred yet. Changes made by other triggers to other rows in the same statement are visible, and as the order of the rows processed is undefined, you need to be cautious. Starting from PostgreSQL 9.3, an error is thrown if a tuple to be updated or deleted has already been updated or...