gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 line
6.5KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ROLLBACK TO SAVEPOINT</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="sql-rollback-prepared.html" title="ROLLBACK PREPARED" /><link rel="next" href="sql-savepoint.html" title="SAVEPOINT" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">ROLLBACK TO SAVEPOINT</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-rollback-prepared.html" title="ROLLBACK PREPARED">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-savepoint.html" title="SAVEPOINT">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-ROLLBACK-TO"><div class="titlepage"></div><a id="id-1.9.3.168.1" class="indexterm"></a><a id="id-1.9.3.168.2" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ROLLBACK TO SAVEPOINT</span></h2><p>ROLLBACK TO SAVEPOINT — roll back to a savepoint</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] <em class="replaceable"><code>savepoint_name</code></em>
  4. </pre></div><div class="refsect1" id="id-1.9.3.168.6"><h2>Description</h2><p>
  5. Roll back all commands that were executed after the savepoint was
  6. established. The savepoint remains valid and can be rolled back to
  7. again later, if needed.
  8. </p><p>
  9. <code class="command">ROLLBACK TO SAVEPOINT</code> implicitly destroys all savepoints that
  10. were established after the named savepoint.
  11. </p></div><div class="refsect1" id="id-1.9.3.168.7"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>savepoint_name</code></em></span></dt><dd><p>
  12. The savepoint to roll back to.
  13. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.168.8"><h2>Notes</h2><p>
  14. Use <a class="xref" href="sql-release-savepoint.html" title="RELEASE SAVEPOINT"><span class="refentrytitle">RELEASE SAVEPOINT</span></a> to destroy a savepoint
  15. without discarding the effects of commands executed after it was
  16. established.
  17. </p><p>
  18. Specifying a savepoint name that has not been established is an error.
  19. </p><p>
  20. Cursors have somewhat non-transactional behavior with respect to
  21. savepoints. Any cursor that is opened inside a savepoint will be closed
  22. when the savepoint is rolled back. If a previously opened cursor is
  23. affected by a <code class="command">FETCH</code> or <code class="command">MOVE</code> command inside a
  24. savepoint that is later rolled back, the cursor remains at the
  25. position that <code class="command">FETCH</code> left it pointing to (that is, the cursor
  26. motion caused by <code class="command">FETCH</code> is not rolled back).
  27. Closing a cursor is not undone by rolling back, either.
  28. However, other side-effects caused by the cursor's query (such as
  29. side-effects of volatile functions called by the query) <span class="emphasis"><em>are</em></span>
  30. rolled back if they occur during a savepoint that is later rolled back.
  31. A cursor whose execution causes a transaction to abort is put in a
  32. cannot-execute state, so while the transaction can be restored using
  33. <code class="command">ROLLBACK TO SAVEPOINT</code>, the cursor can no longer be used.
  34. </p></div><div class="refsect1" id="id-1.9.3.168.9"><h2>Examples</h2><p>
  35. To undo the effects of the commands executed after <code class="literal">my_savepoint</code>
  36. was established:
  37. </p><pre class="programlisting">
  38. ROLLBACK TO SAVEPOINT my_savepoint;
  39. </pre><p>
  40. </p><p>
  41. Cursor positions are not affected by savepoint rollback:
  42. </p><pre class="programlisting">
  43. BEGIN;
  44. DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
  45. SAVEPOINT foo;
  46. FETCH 1 FROM foo;
  47. ?column?
  48. ----------
  49. 1
  50. ROLLBACK TO SAVEPOINT foo;
  51. FETCH 1 FROM foo;
  52. ?column?
  53. ----------
  54. 2
  55. COMMIT;
  56. </pre></div><div class="refsect1" id="id-1.9.3.168.10"><h2>Compatibility</h2><p>
  57. The <acronym class="acronym">SQL</acronym> standard specifies that the key word
  58. <code class="literal">SAVEPOINT</code> is mandatory, but <span class="productname">PostgreSQL</span>
  59. and <span class="productname">Oracle</span> allow it to be omitted. SQL allows
  60. only <code class="literal">WORK</code>, not <code class="literal">TRANSACTION</code>, as a noise word
  61. after <code class="literal">ROLLBACK</code>. Also, SQL has an optional clause
  62. <code class="literal">AND [ NO ] CHAIN</code> which is not currently supported by
  63. <span class="productname">PostgreSQL</span>. Otherwise, this command conforms to
  64. the SQL standard.
  65. </p></div><div class="refsect1" id="id-1.9.3.168.11"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-begin.html" title="BEGIN"><span class="refentrytitle">BEGIN</span></a>, <a class="xref" href="sql-commit.html" title="COMMIT"><span class="refentrytitle">COMMIT</span></a>, <a class="xref" href="sql-release-savepoint.html" title="RELEASE SAVEPOINT"><span class="refentrytitle">RELEASE SAVEPOINT</span></a>, <a class="xref" href="sql-rollback.html" title="ROLLBACK"><span class="refentrytitle">ROLLBACK</span></a>, <a class="xref" href="sql-savepoint.html" title="SAVEPOINT"><span class="refentrytitle">SAVEPOINT</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-rollback-prepared.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-savepoint.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ROLLBACK PREPARED </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> SAVEPOINT</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1