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
Type The type of the trigger being configured. Possible values are Ordinary trigger and Constraint trigger. Extra attributes are enabled when configuring constraint triggers.
Events Set of events when the trigger should be executed.
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.
Function Function that will be executed when the trigger is fired. The function must return trigger and take no argument.
Transition table names Defines custom names for the transition tables (relations) OLD and NEW during the trigger execution.
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.
Constraint This tab handles the constraint trigger attributes. 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.

Mar 17, 2020 at 11:13