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 "SAVEPOINT" "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
SAVEPOINT \- define a new savepoint within the current transaction
24
.\" savepoints: defining
28
SAVEPOINT \fIsavepoint_name\fR
33
establishes a new savepoint within the current transaction\&.
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\&.
40
The name to give to the new savepoint\&.
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\&.
50
Savepoints can only be established when inside a transaction block\&. There can be multiple savepoints defined within a transaction\&.
53
To establish a savepoint and later undo the effects of all commands executed after it was established:
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);
71
The above transaction will insert the values 1 and 3, but not 2\&.
73
To establish and later destroy a savepoint:
80
INSERT INTO table1 VALUES (3);
81
SAVEPOINT my_savepoint;
82
INSERT INTO table1 VALUES (4);
83
RELEASE SAVEPOINT my_savepoint;
90
The above transaction will insert both 3 and 4\&.
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
96
will cause the older one to again become accessible to
99
RELEASE SAVEPOINT\&.) Otherwise,
101
is fully SQL conforming\&.
103
\fBBEGIN\fR(7), \fBCOMMIT\fR(7), RELEASE SAVEPOINT (\fBRELEASE_SAVEPOINT\fR(7)), \fBROLLBACK\fR(7), ROLLBACK TO SAVEPOINT (\fBROLLBACK_TO_SAVEPOINT\fR(7))