~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/man7/SET_CONSTRAINTS.7

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'\" t
 
2
.\"     Title: SET CONSTRAINTS
 
3
.\"    Author: The PostgreSQL Global Development Group
 
4
.\" Generator: DocBook XSL Stylesheets v1.75.1 <http://docbook.sf.net/>
 
5
.\"      Date: 2011-04-27
 
6
.\"    Manual: PostgreSQL 9.1beta1 Documentation
 
7
.\"    Source: PostgreSQL 9.1beta1
 
8
.\"  Language: English
 
9
.\"
 
10
.TH "SET CONSTRAINTS" "7" "2011-04-27" "PostgreSQL 9.1beta1" "PostgreSQL 9.1beta1 Documentation"
 
11
.\" -----------------------------------------------------------------
 
12
.\" * set default formatting
 
13
.\" -----------------------------------------------------------------
 
14
.\" disable hyphenation
 
15
.nh
 
16
.\" disable justification (adjust text to left margin only)
 
17
.ad l
 
18
.\" -----------------------------------------------------------------
 
19
.\" * MAIN CONTENT STARTS HERE *
 
20
.\" -----------------------------------------------------------------
 
21
.SH "NAME"
 
22
SET_CONSTRAINTS \- set constraint check timing for the current transaction
 
23
.\" SET CONSTRAINTS
 
24
.SH "SYNOPSIS"
 
25
.sp
 
26
.nf
 
27
SET CONSTRAINTS { ALL | \fIname\fR [, \&.\&.\&.] } { DEFERRED | IMMEDIATE }
 
28
.fi
 
29
.SH "DESCRIPTION"
 
30
.PP
 
31
SET CONSTRAINTS
 
32
sets the behavior of constraint checking within the current transaction\&.
 
33
IMMEDIATE
 
34
constraints are checked at the end of each statement\&.
 
35
DEFERRED
 
36
constraints are not checked until transaction commit\&. Each constraint has its own
 
37
IMMEDIATE
 
38
or
 
39
DEFERRED
 
40
mode\&.
 
41
.PP
 
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
 
46
IMMEDIATE
 
47
and is not affected by the
 
48
SET CONSTRAINTS
 
49
command\&. The first two classes start every transaction in the indicated mode, but their behavior can be changed within a transaction by
 
50
SET CONSTRAINTS\&.
 
51
.PP
 
52
SET CONSTRAINTS
 
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\&.
 
54
SET CONSTRAINTS ALL
 
55
changes the mode of all deferrable constraints\&.
 
56
.PP
 
57
When
 
58
SET CONSTRAINTS
 
59
changes the mode of a constraint from
 
60
DEFERRED
 
61
to
 
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
 
63
SET CONSTRAINTS
 
64
command\&. If any such constraint is violated, the
 
65
SET CONSTRAINTS
 
66
fails (and does not change the constraint mode)\&. Thus,
 
67
SET CONSTRAINTS
 
68
can be used to force checking of constraints to occur at a specific point in a transaction\&.
 
69
.PP
 
70
Currently, only
 
71
UNIQUE,
 
72
PRIMARY KEY,
 
73
REFERENCES
 
74
(foreign key), and
 
75
EXCLUDE
 
76
constraints are affected by this setting\&.
 
77
NOT NULL
 
78
and
 
79
CHECK
 
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
 
82
DEFERRABLE
 
83
are also checked immediately\&.
 
84
.PP
 
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\&.
 
88
.SH "NOTES"
 
89
.PP
 
90
Because
 
91
PostgreSQL
 
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
 
93
SET CONSTRAINTS
 
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\&.
 
95
.PP
 
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\&.
 
98
.SH "COMPATIBILITY"
 
99
.PP
 
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
 
102
NOT NULL
 
103
and
 
104
CHECK
 
105
constraints\&. Also,
 
106
PostgreSQL
 
107
checks non\-deferrable uniqueness constraints immediately, not at end of statement as the standard would suggest\&.