1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>SAVEPOINT</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="sql-commands.html" title="SQL Commands">
<link rel="prev" href="sql-rollback-to.html" title="ROLLBACK TO SAVEPOINT">
<link rel="next" href="sql-select.html" title="SELECT">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
<a name="sql-savepoint"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>SAVEPOINT — define a new savepoint within the current transaction</p>
</div>
<a name="id782498"></a><a name="id782507"></a><div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">SAVEPOINT <em class="replaceable"><code>savepoint_name</code></em></pre>
</div>
<div class="refsect1" lang="en">
<a name="id782530"></a><h2>Description</h2>
<p> <code class="command">SAVEPOINT</code> establishes a new savepoint within
the current transaction.
</p>
<p> 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.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id782550"></a><h2>Parameters</h2>
<div class="variablelist"><dl>
<dt><span class="term"><em class="replaceable"><code>savepoint_name</code></em></span></dt>
<dd><p> The name to give to the new savepoint.
</p></dd>
</dl></div>
</div>
<div class="refsect1" lang="en">
<a name="id782565"></a><h2>Notes</h2>
<p> Use <a href="sql-rollback-to.html">ROLLBACK TO SAVEPOINT</a> to
rollback to a savepoint. Use <a href="sql-release-savepoint.html">RELEASE SAVEPOINT</a> to destroy a savepoint, keeping
the effects of commands executed after it was established.
</p>
<p> Savepoints can only be established when inside a transaction block.
There can be multiple savepoints defined within a transaction.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id782602"></a><h2>Examples</h2>
<p> To establish a savepoint and later undo the effects of all commands executed
after it was established:
</p>
<pre class="programlisting">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;</pre>
<p>
The above transaction will insert the values 1 and 3, but not 2.
</p>
<p> To establish and later destroy a savepoint:
</p>
<pre class="programlisting">BEGIN;
INSERT INTO table1 VALUES (3);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (4);
RELEASE SAVEPOINT my_savepoint;
COMMIT;</pre>
<p>
The above transaction will insert both 3 and 4.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id782634"></a><h2>Compatibility</h2>
<p> SQL requires a savepoint to be destroyed automatically when another
savepoint with the same name is established. In
<span class="productname">PostgreSQL</span>, the old savepoint is kept, though only the more
recent one will be used when rolling back or releasing. (Releasing the
newer savepoint will cause the older one to again become accessible to
<code class="command">ROLLBACK TO SAVEPOINT</code> and <code class="command">RELEASE SAVEPOINT</code>.)
Otherwise, <code class="command">SAVEPOINT</code> is fully SQL conforming.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id782673"></a><h2>See Also</h2>
<span class="simplelist"><a href="sql-begin.html">BEGIN</a>, <a href="sql-commit.html">COMMIT</a>, <a href="sql-release-savepoint.html">RELEASE SAVEPOINT</a>, <a href="sql-rollback.html">ROLLBACK</a>, <a href="sql-rollback-to.html">ROLLBACK TO SAVEPOINT</a></span>
</div>
</div></body>
</html>
|