3 PostgreSQL documentation
6 <refentry id=
"SQL-CREATECONSTRAINT">
8 <refentrytitle id=
"sql-createconstraint-title">CREATE CONSTRAINT TRIGGER
</refentrytitle>
9 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
13 <refname>CREATE CONSTRAINT TRIGGER
</refname>
14 <refpurpose>define a new constraint trigger
</refpurpose>
17 <indexterm zone=
"sql-createconstraint">
18 <primary>CREATE CONSTRAINT TRIGGER
</primary>
23 CREATE CONSTRAINT TRIGGER
<replaceable class=
"parameter">name
</replaceable>
24 AFTER
<replaceable class=
"parameter">event
</replaceable> [ OR ... ]
25 ON
<replaceable class=
"parameter">table_name
</replaceable>
26 [ FROM
<replaceable class=
"parameter">referenced_table_name
</replaceable> ]
27 { NOT DEFERRABLE | [ DEFERRABLE ] { INITIALLY IMMEDIATE | INITIALLY DEFERRED } }
29 EXECUTE PROCEDURE
<replaceable class=
"parameter">funcname
</replaceable> (
<replaceable class=
"parameter">arguments
</replaceable> )
34 <title>Description
</title>
37 <command>CREATE CONSTRAINT TRIGGER
</command> creates a
38 <firstterm>constraint trigger<
/>. This is the same as a regular trigger
39 except that the timing of the trigger firing can be adjusted using
40 <xref linkend=
"SQL-SET-CONSTRAINTS" endterm=
"SQL-SET-CONSTRAINTS-TITLE">.
41 Constraint triggers must be
<literal>AFTER ROW<
/> triggers. They can
42 be fired either at the end of the statement causing the triggering event,
43 or at the end of the containing transaction; in the latter case they are
44 said to be
<firstterm>deferred<
/>. A pending deferred-trigger firing can
45 also be forced to happen immediately by using
<command>SET CONSTRAINTS<
/>.
50 <title>Parameters
</title>
54 <term><replaceable class=
"PARAMETER">name
</replaceable></term>
57 The name of the constraint trigger. This is also the name to use
58 when modifying the trigger's behavior using
<command>SET CONSTRAINTS<
/>.
59 The name cannot be schema-qualified
— the trigger inherits the
66 <term><replaceable class=
"PARAMETER">event
</replaceable></term>
69 One of
<literal>INSERT
</literal>,
<literal>UPDATE
</literal>, or
70 <literal>DELETE
</literal>; this specifies the event that will fire the
71 trigger. Multiple events can be specified using
<literal>OR
</literal>.
77 <term><replaceable class=
"PARAMETER">table_name
</replaceable></term>
80 The (possibly schema-qualified) name of the table in which
81 the triggering events occur.
87 <term><replaceable class=
"PARAMETER">referenced_table_name
</replaceable></term>
90 The (possibly schema-qualified) name of another table referenced by the
91 constraint. This option is used for foreign-key constraints and is not
92 recommended for general use.
98 <term><literal>DEFERRABLE
</literal></term>
99 <term><literal>NOT DEFERRABLE
</literal></term>
100 <term><literal>INITIALLY IMMEDIATE
</literal></term>
101 <term><literal>INITIALLY DEFERRED
</literal></term>
104 The default timing of the trigger.
105 See the
<xref linkend=
"SQL-CREATETABLE" endterm=
"SQL-CREATETABLE-TITLE">
106 documentation for details of these constraint options.
112 <term><replaceable class=
"PARAMETER">funcname
</replaceable></term>
115 The function to call when the trigger is fired. See
<xref
116 linkend=
"SQL-CREATETRIGGER" endterm=
"SQL-CREATETRIGGER-TITLE"> for
123 <term><replaceable class=
"PARAMETER">arguments
</replaceable></term>
126 Optional argument strings to pass to the trigger function. See
<xref
127 linkend=
"SQL-CREATETRIGGER" endterm=
"SQL-CREATETRIGGER-TITLE"> for
136 <title>Compatibility
</title>
138 <command>CREATE CONSTRAINT TRIGGER
</command> is a
139 <productname>PostgreSQL
</productname> extension of the
<acronym>SQL<
/>
145 <title>See Also
</title>
147 <simplelist type=
"inline">
148 <member><xref linkend=
"sql-createtrigger" endterm=
"sql-createtrigger-title"></member>
149 <member><xref linkend=
"sql-droptrigger" endterm=
"sql-droptrigger-title"></member>
150 <member><xref linkend=
"sql-set-constraints" endterm=
"sql-set-constraints-title"></member>