]> begriffs open source - ai-pg/blob - full-docs/txt/plpython-trigger.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / plpython-trigger.txt
1
2 44.5. Trigger Functions #
3
4    When a function is used as a trigger, the dictionary TD contains
5    trigger-related values:
6
7    TD["event"]
8           contains the event as a string: INSERT, UPDATE, DELETE, or
9           TRUNCATE.
10
11    TD["when"]
12           contains one of BEFORE, AFTER, or INSTEAD OF.
13
14    TD["level"]
15           contains ROW or STATEMENT.
16
17    TD["new"]
18           TD["old"]
19           For a row-level trigger, one or both of these fields contain the
20           respective trigger rows, depending on the trigger event.
21
22    TD["name"]
23           contains the trigger name.
24
25    TD["table_name"]
26           contains the name of the table on which the trigger occurred.
27
28    TD["table_schema"]
29           contains the schema of the table on which the trigger occurred.
30
31    TD["relid"]
32           contains the OID of the table on which the trigger occurred.
33
34    TD["args"]
35           If the CREATE TRIGGER command included arguments, they are
36           available in TD["args"][0] to TD["args"][n-1].
37
38    If TD["when"] is BEFORE or INSTEAD OF and TD["level"] is ROW, you can
39    return None or "OK" from the Python function to indicate the row is
40    unmodified, "SKIP" to abort the event, or if TD["event"] is INSERT or
41    UPDATE you can return "MODIFY" to indicate you've modified the new row.
42    Otherwise the return value is ignored.