]> begriffs open source - ai-pg/blob - full-docs/txt/trigger-datachanges.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / trigger-datachanges.txt
1
2 37.2. Visibility of Data Changes #
3
4    If you execute SQL commands in your trigger function, and these
5    commands access the table that the trigger is for, then you need to be
6    aware of the data visibility rules, because they determine whether
7    these SQL commands will see the data change that the trigger is fired
8    for. Briefly:
9      * Statement-level triggers follow simple visibility rules: none of
10        the changes made by a statement are visible to statement-level
11        BEFORE triggers, whereas all modifications are visible to
12        statement-level AFTER triggers.
13      * The data change (insertion, update, or deletion) causing the
14        trigger to fire is naturally not visible to SQL commands executed
15        in a row-level BEFORE trigger, because it hasn't happened yet.
16      * However, SQL commands executed in a row-level BEFORE trigger will
17        see the effects of data changes for rows previously processed in
18        the same outer command. This requires caution, since the ordering
19        of these change events is not in general predictable; an SQL
20        command that affects multiple rows can visit the rows in any order.
21      * Similarly, a row-level INSTEAD OF trigger will see the effects of
22        data changes made by previous firings of INSTEAD OF triggers in the
23        same outer command.
24      * When a row-level AFTER trigger is fired, all data changes made by
25        the outer command are already complete, and are visible to the
26        invoked trigger function.
27
28    If your trigger function is written in any of the standard procedural
29    languages, then the above statements apply only if the function is
30    declared VOLATILE. Functions that are declared STABLE or IMMUTABLE will
31    not see changes made by the calling command in any case.
32
33    Further information about data visibility rules can be found in
34    Section 45.5. The example in Section 37.4 contains a demonstration of
35    these rules.