3.5. Triggers

Triggers are objects associated to a table which are used to execute operations stored in special functions when some operation (or event) happens on a single row or on the entire table. The trigger can be activated before or after the following events: INSERT, DELETE, UPDATE or TRUNCATE. There is still a special behavior of a trigger that makes it able to execute the associated procedure instead of a certain event, this modality of trigger is known as constraint trigger.

Attribute Description
Execution The moment when the trigger must be fired. Possible values are BEFORE, AFTER and INSTEAD OF (this value is available only for constraint triggers).
FOR EACH ROW The trigger must be executed for each time a row changes.
Event Set of events when the trigger should be executed.
Function Function that will be executed when the trigger is fired. The function must return trigger and take no argument.
Constraint Creates a constraint trigger. Constraint triggers works like a regular trigger but they can have the firing time adjusted through the command SET CONSTRAINTS.
Deferrable Indicates if the constraint trigger can be deferred or not. The deferral mode is configurable only when this option is checked and the accepted values are INITIALLY IMMEDIATE and INITIALLY DEFERRED.
Referenced Table Table referenced by the constraint trigger.
Condition A boolean expression that determines when the trigger function will actually be executed.
Arguments A set of literal arguments optionally passed to the trigger at runtime. These arguments must be treated inside the trigger's function.
Columns List of columns of the trigger's owner table that, in case of an UPDATE on them, will fire the trigger. If the trigger is configured with INSTEAD OF it can't be used with a list of columns.

Jan 3, 2020 at 12:33