Make LC_COLLATE and LC_CTYPE database-level settings. Collation and
[PostgreSQL.git] / doc / src / sgml / ref / create_constraint.sgml
blob5469eb83e92e590699e2084c0bdb65a24be401ef
1 <!--
2 $PostgreSQL$
3 PostgreSQL documentation
4 -->
6 <refentry id="SQL-CREATECONSTRAINT">
7 <refmeta>
8 <refentrytitle id="sql-createconstraint-title">CREATE CONSTRAINT TRIGGER</refentrytitle>
9 <refmiscinfo>SQL - Language Statements</refmiscinfo>
10 </refmeta>
12 <refnamediv>
13 <refname>CREATE CONSTRAINT TRIGGER</refname>
14 <refpurpose>define a new constraint trigger</refpurpose>
15 </refnamediv>
17 <indexterm zone="sql-createconstraint">
18 <primary>CREATE CONSTRAINT TRIGGER</primary>
19 </indexterm>
21 <refsynopsisdiv>
22 <synopsis>
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 } }
28 FOR EACH ROW
29 EXECUTE PROCEDURE <replaceable class="parameter">funcname</replaceable> ( <replaceable class="parameter">arguments</replaceable> )
30 </synopsis>
31 </refsynopsisdiv>
33 <refsect1>
34 <title>Description</title>
36 <para>
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</>.
46 </para>
47 </refsect1>
49 <refsect1>
50 <title>Parameters</title>
52 <variablelist>
53 <varlistentry>
54 <term><replaceable class="PARAMETER">name</replaceable></term>
55 <listitem>
56 <para>
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 &mdash; the trigger inherits the
60 schema of its table.
61 </para>
62 </listitem>
63 </varlistentry>
65 <varlistentry>
66 <term><replaceable class="PARAMETER">event</replaceable></term>
67 <listitem>
68 <para>
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>.
72 </para>
73 </listitem>
74 </varlistentry>
76 <varlistentry>
77 <term><replaceable class="PARAMETER">table_name</replaceable></term>
78 <listitem>
79 <para>
80 The (possibly schema-qualified) name of the table in which
81 the triggering events occur.
82 </para>
83 </listitem>
84 </varlistentry>
86 <varlistentry>
87 <term><replaceable class="PARAMETER">referenced_table_name</replaceable></term>
88 <listitem>
89 <para>
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.
93 </para>
94 </listitem>
95 </varlistentry>
97 <varlistentry>
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>
102 <listitem>
103 <para>
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.
107 </para>
108 </listitem>
109 </varlistentry>
111 <varlistentry>
112 <term><replaceable class="PARAMETER">funcname</replaceable></term>
113 <listitem>
114 <para>
115 The function to call when the trigger is fired. See <xref
116 linkend="SQL-CREATETRIGGER" endterm="SQL-CREATETRIGGER-TITLE"> for
117 details.
118 </para>
119 </listitem>
120 </varlistentry>
122 <varlistentry>
123 <term><replaceable class="PARAMETER">arguments</replaceable></term>
124 <listitem>
125 <para>
126 Optional argument strings to pass to the trigger function. See <xref
127 linkend="SQL-CREATETRIGGER" endterm="SQL-CREATETRIGGER-TITLE"> for
128 details.
129 </para>
130 </listitem>
131 </varlistentry>
132 </variablelist>
133 </refsect1>
135 <refsect1>
136 <title>Compatibility</title>
137 <para>
138 <command>CREATE CONSTRAINT TRIGGER</command> is a
139 <productname>PostgreSQL</productname> extension of the <acronym>SQL</>
140 standard.
141 </para>
142 </refsect1>
144 <refsect1>
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>
151 </simplelist>
152 </refsect1>
153 </refentry>