gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

54 行
5.8KB

  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>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-to.html" title="ROLLBACK TO SAVEPOINT" /><link rel="next" href="sql-security-label.html" title="SECURITY LABEL" /></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">SAVEPOINT</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-rollback-to.html" title="ROLLBACK TO SAVEPOINT">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-security-label.html" title="SECURITY LABEL">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-SAVEPOINT"><div class="titlepage"></div><a id="id-1.9.3.169.1" class="indexterm"></a><a id="id-1.9.3.169.2" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">SAVEPOINT</span></h2><p>SAVEPOINT — define a new savepoint within the current transaction</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. SAVEPOINT <em class="replaceable"><code>savepoint_name</code></em>
  4. </pre></div><div class="refsect1" id="id-1.9.3.169.6"><h2>Description</h2><p>
  5. <code class="command">SAVEPOINT</code> establishes a new savepoint within
  6. the current transaction.
  7. </p><p>
  8. A savepoint is a special mark inside a transaction that allows all commands
  9. that are executed after it was established to be rolled back, restoring
  10. the transaction state to what it was at the time of the savepoint.
  11. </p></div><div class="refsect1" id="id-1.9.3.169.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 name to give to the new savepoint.
  13. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.169.8"><h2>Notes</h2><p>
  14. Use <a class="xref" href="sql-rollback-to.html" title="ROLLBACK TO SAVEPOINT"><span class="refentrytitle">ROLLBACK TO SAVEPOINT</span></a> to
  15. rollback to a savepoint. Use <a class="xref" href="sql-release-savepoint.html" title="RELEASE SAVEPOINT"><span class="refentrytitle">RELEASE SAVEPOINT</span></a>
  16. to destroy a savepoint, keeping
  17. the effects of commands executed after it was established.
  18. </p><p>
  19. Savepoints can only be established when inside a transaction block.
  20. There can be multiple savepoints defined within a transaction.
  21. </p></div><div class="refsect1" id="id-1.9.3.169.9"><h2>Examples</h2><p>
  22. To establish a savepoint and later undo the effects of all commands executed
  23. after it was established:
  24. </p><pre class="programlisting">
  25. BEGIN;
  26. INSERT INTO table1 VALUES (1);
  27. SAVEPOINT my_savepoint;
  28. INSERT INTO table1 VALUES (2);
  29. ROLLBACK TO SAVEPOINT my_savepoint;
  30. INSERT INTO table1 VALUES (3);
  31. COMMIT;
  32. </pre><p>
  33. The above transaction will insert the values 1 and 3, but not 2.
  34. </p><p>
  35. To establish and later destroy a savepoint:
  36. </p><pre class="programlisting">
  37. BEGIN;
  38. INSERT INTO table1 VALUES (3);
  39. SAVEPOINT my_savepoint;
  40. INSERT INTO table1 VALUES (4);
  41. RELEASE SAVEPOINT my_savepoint;
  42. COMMIT;
  43. </pre><p>
  44. The above transaction will insert both 3 and 4.
  45. </p></div><div class="refsect1" id="id-1.9.3.169.10"><h2>Compatibility</h2><p>
  46. SQL requires a savepoint to be destroyed automatically when another
  47. savepoint with the same name is established. In
  48. <span class="productname">PostgreSQL</span>, the old savepoint is kept, though only the more
  49. recent one will be used when rolling back or releasing. (Releasing the
  50. newer savepoint with <code class="command">RELEASE SAVEPOINT</code> will cause the older one
  51. to again become accessible to <code class="command">ROLLBACK TO SAVEPOINT</code> and
  52. <code class="command">RELEASE SAVEPOINT</code>.) Otherwise, <code class="command">SAVEPOINT</code> is
  53. fully SQL conforming.
  54. </p></div><div class="refsect1" id="id-1.9.3.169.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-rollback-to.html" title="ROLLBACK TO SAVEPOINT"><span class="refentrytitle">ROLLBACK TO 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-to.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-security-label.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ROLLBACK TO SAVEPOINT </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> SECURITY LABEL</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1