Skip to main content
Version: 1.0.0

3.5. Triggers

Triggers are objects associated with a table that are used to execute operations stored in special functions when some operation (or event) happens on a single row or over 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 kind of trigger is known as constraint trigger.

AttributeDescription
TypeThe type of trigger that is being configured. Possible values are Ordinary trigger and Constraint trigger. Extra attributes are enabled when configuring constraint triggers.
EventsSet of events when the trigger should be executed.
ExecutionThe 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 ROWThe trigger must be executed each time a row changes.
FunctionFunction that will be executed when the trigger is fired. The function must return trigger and take no argument.
Transition table namesDefines custom names for the transition tables (relations) OLD and NEW during the trigger execution.
ArgumentsA set of literal arguments optionally passed to the trigger at runtime. These arguments must be treated inside the trigger's function.
ColumnsList of columns of the trigger's owner table that will cause the trigger to be activated in case of an UPDATE on those columns. If the trigger is configured with INSTEAD OF it can't be used with a list of columns.
ConstraintThis tab handles the constraint trigger attributes. Constraint triggers work like a regular triggers but they can have the firing time adjusted through the command SET CONSTRAINTS.
DeferrableIndicates 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 TableTable referenced by the constraint trigger.
ConditionA boolean expression that determines when the trigger function will actually be executed.

References​

Trigger DDL

https://www.postgresql.org/docs/current/static/sql-createtrigger.html