2
.\" Title: SET CONSTRAINTS
3
.\" Author: The PostgreSQL Global Development Group
4
.\" Generator: DocBook XSL Stylesheets v1.75.1 <http://docbook.sf.net/>
6
.\" Manual: PostgreSQL 9.1beta1 Documentation
7
.\" Source: PostgreSQL 9.1beta1
10
.TH "SET CONSTRAINTS" "7" "2011-04-27" "PostgreSQL 9.1beta1" "PostgreSQL 9.1beta1 Documentation"
11
.\" -----------------------------------------------------------------
12
.\" * set default formatting
13
.\" -----------------------------------------------------------------
14
.\" disable hyphenation
16
.\" disable justification (adjust text to left margin only)
18
.\" -----------------------------------------------------------------
19
.\" * MAIN CONTENT STARTS HERE *
20
.\" -----------------------------------------------------------------
22
SET_CONSTRAINTS \- set constraint check timing for the current transaction
27
SET CONSTRAINTS { ALL | \fIname\fR [, \&.\&.\&.] } { DEFERRED | IMMEDIATE }
32
sets the behavior of constraint checking within the current transaction\&.
34
constraints are checked at the end of each statement\&.
36
constraints are not checked until transaction commit\&. Each constraint has its own
42
Upon creation, a constraint is given one of three characteristics:
43
DEFERRABLE INITIALLY DEFERRED,
44
DEFERRABLE INITIALLY IMMEDIATE, or
45
NOT DEFERRABLE\&. The third class is always
47
and is not affected by the
49
command\&. The first two classes start every transaction in the indicated mode, but their behavior can be changed within a transaction by
53
with a list of constraint names changes the mode of just those constraints (which must all be deferrable)\&. Each constraint name can be schema\-qualified\&. The current schema search path is used to find the first matching name if no schema name is specified\&.
55
changes the mode of all deferrable constraints\&.
59
changes the mode of a constraint from
62
IMMEDIATE, the new mode takes effect retroactively: any outstanding data modifications that would have been checked at the end of the transaction are instead checked during the execution of the
64
command\&. If any such constraint is violated, the
66
fails (and does not change the constraint mode)\&. Thus,
68
can be used to force checking of constraints to occur at a specific point in a transaction\&.
76
constraints are affected by this setting\&.
80
constraints are always checked immediately when a row is inserted or modified (\fInot\fR
81
at the end of the statement)\&. Uniqueness and exclusion constraints that have not been declared
83
are also checked immediately\&.
85
The firing of triggers that are declared as
86
\(lqconstraint triggers\(rq
87
is also controlled by this setting \(em they fire at the same time that the associated constraint should be checked\&.
92
does not require constraint names to be unique within a schema (but only per\-table), it is possible that there is more than one match for a specified constraint name\&. In this case
94
will act on all matches\&. For a non\-schema\-qualified name, once a match or matches have been found in some schema in the search path, schemas appearing later in the path are not searched\&.
96
This command only alters the behavior of constraints within the current transaction\&. Thus, if you execute this command outside of a transaction block (BEGIN/COMMIT
97
pair), it will not appear to have any effect\&.
100
This command complies with the behavior defined in the SQL standard, except for the limitation that, in
101
PostgreSQL, it does not apply to
107
checks non\-deferrable uniqueness constraints immediately, not at end of statement as the standard would suggest\&.