2 .\" Title: SET CONSTRAINTS
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "SET CONSTRAINTS" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 SET_CONSTRAINTS \- set constraint check timing for the current transaction
35 SET CONSTRAINTS { ALL | \fIname\fR [, \&.\&.\&.] } { DEFERRED | IMMEDIATE }
40 sets the behavior of constraint checking within the current transaction\&.
42 constraints are checked at the end of each statement\&.
44 constraints are not checked until transaction commit\&. Each constraint has its own
50 Upon creation, a constraint is given one of three characteristics:
51 DEFERRABLE INITIALLY DEFERRED,
52 DEFERRABLE INITIALLY IMMEDIATE, or
53 NOT DEFERRABLE\&. The third class is always
55 and is not affected by the
57 command\&. The first two classes start every transaction in the indicated mode, but their behavior can be changed within a transaction by
58 \fBSET CONSTRAINTS\fR\&.
61 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\&.
62 \fBSET CONSTRAINTS ALL\fR
63 changes the mode of all deferrable constraints\&.
67 changes the mode of a constraint from
70 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
72 command\&. If any such constraint is violated, the
74 fails (and does not change the constraint mode)\&. Thus,
76 can be used to force checking of constraints to occur at a specific point in a transaction\&.
84 constraints are affected by this setting\&.
88 constraints are always checked immediately when a row is inserted or modified (\fInot\fR
89 at the end of the statement)\&. Uniqueness and exclusion constraints that have not been declared
91 are also checked immediately\&.
93 The firing of triggers that are declared as
94 \(lqconstraint triggers\(rq
95 is also controlled by this setting \(em they fire at the same time that the associated constraint should be checked\&.
100 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
101 \fBSET CONSTRAINTS\fR
102 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\&.
104 This command only alters the behavior of constraints within the current transaction\&. Issuing this outside of a transaction block emits a warning and otherwise has no effect\&.
107 This command complies with the behavior defined in the SQL standard, except for the limitation that, in
108 PostgreSQL, it does not apply to
114 checks non\-deferrable uniqueness constraints immediately, not at end of statement as the standard would suggest\&.