- details.
-CREATE TRIGGER name { BEFORE | AFTER | INSTEAD OF } { event [ OR ... ] }
+CREATE [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF } { event [ OR ... ] }
ON table [ FOR [ EACH ] { ROW | STATEMENT } ]
+ [ FROM referenced_table_name ]
+ { NOT DEFERRABLE | [ DEFERRABLE ] { INITIALLY IMMEDIATE | INITIALLY DEFERRED } }
[ WHEN ( condition ) ]
EXECUTE PROCEDURE function_name ( arguments )
they will be fired in alphabetical order by name.
+ When the CONSTRAINT> option is specified, this command creates a
+ constraint trigger>. This is the same as a regular trigger
+ except that the timing of the trigger firing can be adjusted using
+ .
+ Constraint triggers must be AFTER ROW> triggers. They can
+ be fired either at the end of the statement causing the triggering event,
+ or at the end of the containing transaction; in the latter case they are
+ said to be deferred>. A pending deferred-trigger firing can
+ also be forced to happen immediately by using SET CONSTRAINTS>.
+ Constraint triggers are expected to raise an exception when the constraints
+ they implement are violated.
+
+
SELECT does not modify any rows so you cannot
create SELECT triggers. Rules and views are more
The name to give the new trigger. This must be distinct from
the name of any other trigger for the same table.
+ The name cannot be schema-qualified — the trigger inherits the
+ schema of its table. For a constraint trigger, this is also the name to
+ use when modifying the trigger's behavior using
+ SET CONSTRAINTS>.
Determines whether the function is called before, after, or instead of
- the event.
+ the event. A constraint trigger can only be specified as
+ AFTER>.
+
+ referenced_table_name
+
+ The (possibly schema-qualified) name of another table referenced by the
+ constraint. This option is used for foreign-key constraints and is not
+ recommended for general use. This can only be specified for
+ constraint triggers.
+
+
+
+
+
+ DEFERRABLE
+ NOT DEFERRABLE
+ INITIALLY IMMEDIATE
+ INITIALLY DEFERRED
+
+ The default timing of the trigger.
+ See the documentation for details of
+ these constraint options. This can only be specified for constraint
+ triggers.
+
+
+
+
FOR EACH ROW
FOR EACH STATEMENT
This specifies whether the trigger procedure should be fired
once for every row affected by the trigger event, or just once
per SQL statement. If neither is specified, FOR EACH
- STATEMENT is the default.
+ STATEMENT is the default. Constraint triggers can only
+ be specified FOR EACH ROW>.
Currently, WHEN expressions cannot contain
subqueries.
+
+ Note that for constraint triggers, evaluation of the WHEN>
+ condition is not deferred, but occurs immediately after the row update
+ operation is performed. If the condition does not evaluate to true then
+ the trigger is not queued for deferred execution.
+
ability to define statement-level triggers on views.
+ CREATE CONSTRAINT TRIGGER is a
+
PostgreSQL extension of the
SQL>
+ standard.
+
+
+