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

« back to all changes in this revision

Viewing changes to doc/src/sgml/man7/SAVEPOINT.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: SAVEPOINT
 
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 "SAVEPOINT" "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
SAVEPOINT \- define a new savepoint within the current transaction
 
23
.\" SAVEPOINT
 
24
.\" savepoints: defining
 
25
.SH "SYNOPSIS"
 
26
.sp
 
27
.nf
 
28
SAVEPOINT \fIsavepoint_name\fR
 
29
.fi
 
30
.SH "DESCRIPTION"
 
31
.PP
 
32
SAVEPOINT
 
33
establishes a new savepoint within the current transaction\&.
 
34
.PP
 
35
A savepoint is a special mark inside a transaction that allows all commands that are executed after it was established to be rolled back, restoring the transaction state to what it was at the time of the savepoint\&.
 
36
.SH "PARAMETERS"
 
37
.PP
 
38
\fIsavepoint_name\fR
 
39
.RS 4
 
40
The name to give to the new savepoint\&.
 
41
.RE
 
42
.SH "NOTES"
 
43
.PP
 
44
Use
 
45
ROLLBACK TO SAVEPOINT (\fBROLLBACK_TO_SAVEPOINT\fR(7))
 
46
to rollback to a savepoint\&. Use
 
47
RELEASE SAVEPOINT (\fBRELEASE_SAVEPOINT\fR(7))
 
48
to destroy a savepoint, keeping the effects of commands executed after it was established\&.
 
49
.PP
 
50
Savepoints can only be established when inside a transaction block\&. There can be multiple savepoints defined within a transaction\&.
 
51
.SH "EXAMPLES"
 
52
.PP
 
53
To establish a savepoint and later undo the effects of all commands executed after it was established:
 
54
.sp
 
55
.if n \{\
 
56
.RS 4
 
57
.\}
 
58
.nf
 
59
BEGIN;
 
60
    INSERT INTO table1 VALUES (1);
 
61
    SAVEPOINT my_savepoint;
 
62
    INSERT INTO table1 VALUES (2);
 
63
    ROLLBACK TO SAVEPOINT my_savepoint;
 
64
    INSERT INTO table1 VALUES (3);
 
65
COMMIT;
 
66
.fi
 
67
.if n \{\
 
68
.RE
 
69
.\}
 
70
.sp
 
71
The above transaction will insert the values 1 and 3, but not 2\&.
 
72
.PP
 
73
To establish and later destroy a savepoint:
 
74
.sp
 
75
.if n \{\
 
76
.RS 4
 
77
.\}
 
78
.nf
 
79
BEGIN;
 
80
    INSERT INTO table1 VALUES (3);
 
81
    SAVEPOINT my_savepoint;
 
82
    INSERT INTO table1 VALUES (4);
 
83
    RELEASE SAVEPOINT my_savepoint;
 
84
COMMIT;
 
85
.fi
 
86
.if n \{\
 
87
.RE
 
88
.\}
 
89
.sp
 
90
The above transaction will insert both 3 and 4\&.
 
91
.SH "COMPATIBILITY"
 
92
.PP
 
93
SQL requires a savepoint to be destroyed automatically when another savepoint with the same name is established\&. In
 
94
PostgreSQL, the old savepoint is kept, though only the more recent one will be used when rolling back or releasing\&. (Releasing the newer savepoint with
 
95
RELEASE SAVEPOINT
 
96
will cause the older one to again become accessible to
 
97
ROLLBACK TO SAVEPOINT
 
98
and
 
99
RELEASE SAVEPOINT\&.) Otherwise,
 
100
SAVEPOINT
 
101
is fully SQL conforming\&.
 
102
.SH "SEE ALSO"
 
103
\fBBEGIN\fR(7), \fBCOMMIT\fR(7), RELEASE SAVEPOINT (\fBRELEASE_SAVEPOINT\fR(7)), \fBROLLBACK\fR(7), ROLLBACK TO SAVEPOINT (\fBROLLBACK_TO_SAVEPOINT\fR(7))