The Trigger Module¶
Trigger¶
-
class
Trigger(**kwargs)¶ base trigger class for inheriting. Meant to be inherited on a per table basis
-
__init__(plpy_wrapper: plpy_wrapper.plpy_wrappers.PLPYWrapper)¶
-
abort()¶ skips the current event (e.g. insert,update)
-
after_delete()¶ run when the context is “after” and “delete”
-
after_insert()¶ run when the context is “after” and “insert”
-
after_update()¶ run when the context is “after” and “update”
-
before_delete()¶ run when the context is “before” and “delete”
-
before_insert()¶ run when the context is “before” and “insert”
-
before_update()¶ run when the context is “before” and “update”
-
execute()¶ executes the method corresponding to the trigger event and the trigger “when”. For example, if when is “BEFORE” and the event is “INSERT”, before_insert would run
-
overwrite_td_new()¶ must be called to persist any changes to the trigger row
Important
call this method when you’re done making all changes needed to the row otherwise changes will not be persisted
-
property
trigger_return_val¶ returns the trigger return value as a string. This string is what the database trigger needs to return
- Return type
str
-
TriggerContext¶
-
class
TriggerContext(**kwargs)¶ wrapper around the
TDdictionary that is available in trigger contexts documentation is taken from https://www.postgresql.org/docs/11/plpython-trigger.html This class should only be initialized in a trigger context.-
__init__(TD: dict)¶
-
property
args¶ trigger arguments If the CREATE TRIGGER command included arguments, they are available in
TD["args"][0]toTD["args"][n-1].- Return type
List[str]
-
property
event¶ the trigger event as a string. Will be one of: INSERT, UPDATE, DELETE, or TRUNCATE
- Return type
str
-
is_changed(field_name)¶ utility method to check if a field was changed as a result of the current trigger event (e.g. update)
- Return type
bool
-
property
level¶ the trigger execution level Can be either ROW or STATEMENT
- Return type
str
-
property
name¶ the name of the running trigger
- Return type
str
-
property
old¶ the state of the row as it was before the trigger fired is
Noneif the event is INSERT or if the trigger execution level is STATEMENT- Return type
Optional[Row]
-
property
relid¶ the
OIDof the table on which the trigger occurred- Return type
int
-
property
table_name¶ the name of the table on which the trigger occurred
- Return type
str
-
property
table_schema¶ the schema of the table on which the trigger occurred
- Return type
str
-
property
when¶ when the trigger fired is one of BEFORE, AFTER, or INSTEAD OF
- Return type
str
-