1SET CONSTRAINTS(7)               SQL Commands               SET CONSTRAINTS(7)
2
3
4

NAME

6       SET  CONSTRAINTS - set constraint checking modes for the current trans‐
7       action
8
9

SYNOPSIS

11       SET CONSTRAINTS { ALL | name [, ...] } { DEFERRED | IMMEDIATE }
12
13

DESCRIPTION

15       SET CONSTRAINTS sets the behavior of  constraint  checking  within  the
16       current  transaction.  IMMEDIATE  constraints are checked at the end of
17       each statement. DEFERRED constraints are not checked until  transaction
18       commit. Each constraint has its own IMMEDIATE or DEFERRED mode.
19
20       Upon  creation,  a  constraint  is  given one of three characteristics:
21       DEFERRABLE INITIALLY DEFERRED, DEFERRABLE INITIALLY IMMEDIATE,  or  NOT
22       DEFERRABLE.  The third class is always IMMEDIATE and is not affected by
23       the SET CONSTRAINTS command. The first two classes start every transac‐
24       tion  in the indicated mode, but their behavior can be changed within a
25       transaction by SET CONSTRAINTS.
26
27       SET CONSTRAINTS with a list of constraint names  changes  the  mode  of
28       just  those  constraints  (which  must  all be deferrable). The current
29       schema search path is used to find the first matching name if no schema
30       name  is  specified.  SET  CONSTRAINTS  ALL  changes  the  mode  of all
31       deferrable constraints.
32
33       When SET CONSTRAINTS changes the mode of a constraint from DEFERRED  to
34       IMMEDIATE,  the  new  mode  takes effect retroactively: any outstanding
35       data modifications that would have been  checked  at  the  end  of  the
36       transaction  are  instead  checked during the execution of the SET CON‐
37       STRAINTS command.  If any such constraint is  violated,  the  SET  CON‐
38       STRAINTS  fails  (and  does  not change the constraint mode). Thus, SET
39       CONSTRAINTS can be used to force checking of constraints to occur at  a
40       specific point in a transaction.
41
42       Currently,  only  foreign key constraints are affected by this setting.
43       Check and unique constraints are  always  effectively  not  deferrable.
44       Triggers   that  are  declared  as  ``constraint  triggers''  are  also
45       affected.
46

NOTES

48       This command only alters the behavior of constraints within the current
49       transaction. Thus, if you execute this command outside of a transaction
50       block (BEGIN/COMMIT pair), it will not appear to have any effect.
51

COMPATIBILITY

53       This command complies with the behavior defined in  the  SQL  standard,
54       except  for the limitation that, in PostgreSQL, it only applies to for‐
55       eign-key constraints.
56
57
58
59SQL - Language Statements         2011-09-22                SET CONSTRAINTS(7)
Impressum