diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:44:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:44:03 +0000 |
commit | 293913568e6a7a86fd1479e1cff8e2ecb58d6568 (patch) | |
tree | fc3b469a3ec5ab71b36ea97cc7aaddb838423a0c /doc/src/sgml/man7/SAVEPOINT.7 | |
parent | Initial commit. (diff) | |
download | postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.tar.xz postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.zip |
Adding upstream version 16.2.upstream/16.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'doc/src/sgml/man7/SAVEPOINT.7')
-rw-r--r-- | doc/src/sgml/man7/SAVEPOINT.7 | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/doc/src/sgml/man7/SAVEPOINT.7 b/doc/src/sgml/man7/SAVEPOINT.7 new file mode 100644 index 0000000..8bf3833 --- /dev/null +++ b/doc/src/sgml/man7/SAVEPOINT.7 @@ -0,0 +1,141 @@ +'\" t +.\" Title: SAVEPOINT +.\" Author: The PostgreSQL Global Development Group +.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/> +.\" Date: 2024 +.\" Manual: PostgreSQL 16.2 Documentation +.\" Source: PostgreSQL 16.2 +.\" Language: English +.\" +.TH "SAVEPOINT" "7" "2024" "PostgreSQL 16.2" "PostgreSQL 16.2 Documentation" +.\" ----------------------------------------------------------------- +.\" * Define some portability stuff +.\" ----------------------------------------------------------------- +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.\" http://bugs.debian.org/507673 +.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" ----------------------------------------------------------------- +.\" * set default formatting +.\" ----------------------------------------------------------------- +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.\" ----------------------------------------------------------------- +.\" * MAIN CONTENT STARTS HERE * +.\" ----------------------------------------------------------------- +.SH "NAME" +SAVEPOINT \- define a new savepoint within the current transaction +.SH "SYNOPSIS" +.sp +.nf +SAVEPOINT \fIsavepoint_name\fR +.fi +.SH "DESCRIPTION" +.PP +\fBSAVEPOINT\fR +establishes a new savepoint within the current transaction\&. +.PP +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\&. +.SH "PARAMETERS" +.PP +\fIsavepoint_name\fR +.RS 4 +The name to give to the new savepoint\&. If savepoints with the same name already exist, they will be inaccessible until newer identically\-named savepoints are released\&. +.RE +.SH "NOTES" +.PP +Use +\fBROLLBACK TO\fR +to rollback to a savepoint\&. Use +\fBRELEASE SAVEPOINT\fR +to destroy a savepoint, keeping the effects of commands executed after it was established\&. +.PP +Savepoints can only be established when inside a transaction block\&. There can be multiple savepoints defined within a transaction\&. +.SH "EXAMPLES" +.PP +To establish a savepoint and later undo the effects of all commands executed after it was established: +.sp +.if n \{\ +.RS 4 +.\} +.nf +BEGIN; + INSERT INTO table1 VALUES (1); + SAVEPOINT my_savepoint; + INSERT INTO table1 VALUES (2); + ROLLBACK TO SAVEPOINT my_savepoint; + INSERT INTO table1 VALUES (3); +COMMIT; +.fi +.if n \{\ +.RE +.\} +.sp +The above transaction will insert the values 1 and 3, but not 2\&. +.PP +To establish and later destroy a savepoint: +.sp +.if n \{\ +.RS 4 +.\} +.nf +BEGIN; + INSERT INTO table1 VALUES (3); + SAVEPOINT my_savepoint; + INSERT INTO table1 VALUES (4); + RELEASE SAVEPOINT my_savepoint; +COMMIT; +.fi +.if n \{\ +.RE +.\} +.sp +The above transaction will insert both 3 and 4\&. +.PP +To use a single savepoint name: +.sp +.if n \{\ +.RS 4 +.\} +.nf +BEGIN; + INSERT INTO table1 VALUES (1); + SAVEPOINT my_savepoint; + INSERT INTO table1 VALUES (2); + SAVEPOINT my_savepoint; + INSERT INTO table1 VALUES (3); + + \-\- rollback to the second savepoint + ROLLBACK TO SAVEPOINT my_savepoint; + SELECT * FROM table1; \-\- shows rows 1 and 2 + + \-\- release the second savepoint + RELEASE SAVEPOINT my_savepoint; + + \-\- rollback to the first savepoint + ROLLBACK TO SAVEPOINT my_savepoint; + SELECT * FROM table1; \-\- shows only row 1 +COMMIT; +.fi +.if n \{\ +.RE +.\} +.sp +The above transaction shows row 3 being rolled back first, then row 2\&. +.SH "COMPATIBILITY" +.PP +SQL requires a savepoint to be destroyed automatically when another savepoint with the same name is established\&. In +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 +\fBRELEASE SAVEPOINT\fR +will cause the older one to again become accessible to +\fBROLLBACK TO SAVEPOINT\fR +and +\fBRELEASE SAVEPOINT\fR\&.) Otherwise, +\fBSAVEPOINT\fR +is fully SQL conforming\&. +.SH "SEE ALSO" +\fBBEGIN\fR(7), \fBCOMMIT\fR(7), RELEASE SAVEPOINT (\fBRELEASE_SAVEPOINT\fR(7)), \fBROLLBACK\fR(7), ROLLBACK TO SAVEPOINT (\fBROLLBACK_TO_SAVEPOINT\fR(7)) |