{"Entry":{"collection":"sql","key":"rollback-to-savepoint","name":"ROLLBACK TO SAVEPOINT","aliases":["rollback-to"],"metadata":{"aliases":["rollback-to"],"changed_in":[],"changes":[{"from":"7.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"8.0"},{"from":"8.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["compatibility"],"removed":[]},"status":"changed","synopsis":null,"to":"8.1"},{"from":"8.2","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"8.3"},{"from":"8.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"9.0"},{"from":"15","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"16"}],"content_hash":"a61e03cc77c74ae6506dc90ad2e7f56e1ef327a3a40a1a38e38e07557d929d10","derived_content_hash":"6b00502b78c08fe0e24728ddb468520bbac22233e69710112e9e720c56839b7f","editorial":{},"first_version":"8.0","group":"transaction","imported_at":"2026-09-30T17:43:39.382582+08:00","last_version":"20","name":"ROLLBACK TO SAVEPOINT","object":"TO SAVEPOINT","position":13011,"present_in":["8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"roll back to a savepoint","purpose_zh":"","related":["begin","commit","release-savepoint","rollback","savepoint"],"repair_provenance":{"original_source_revision":"wiki-repair-20261023:06d0f23ce8e5c9b82a4aac142a78a8cee7d3efd1c001ef0abc59935f04a36d88","receipt_sha256":"02717a36d7ddb120cbc45876313c2fe2558b569fa8f4c598df0f8d4421be4d9c","repair":"wiki-repair-20261023"},"slug":"rollback-to-savepoint","source_rev":"wiki-repair-20261023:49de1065836d503ddc9101dd9e1239f3bce3875e5a35d82583167c3df8827bb6","synopsis":"ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name","verb":"ROLLBACK"}},"Definition":{"Collection":"sql","Key":"rollback-to-savepoint","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"rollback-to-savepoint","SourceRevision":"wiki-repair-20261023:49de1065836d503ddc9101dd9e1239f3bce3875e5a35d82583167c3df8827bb6","Facts":{"anchor":"SQL-ROLLBACK-TO","description_zh":"回滚到一个保存点","description_zh_html":"\u003cpre\u003eROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\n   回滚该保存点建立后执行的所有命令，然后在同一事务层级启动一个新的子事务。该保存点仍然有效，如有需要，之后还可以再次回滚到它。\n  \u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e 会隐式销毁在指定保存点之后建立的所有保存点。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"ZH18-AUTO-ROLLBACK_TO-VARLISTENTRY-1\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003esavepoint_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      要回滚到的保存点名称。\n     \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e\n   使用 \u003ca class=\"link\" href=\"/zh/docs/18/sql-release-savepoint.html\" title=\"RELEASE SAVEPOINT\"\u003e\u003ccode class=\"command\"\u003eRELEASE SAVEPOINT\u003c/code\u003e\u003c/a\u003e 可以销毁一个保存点，而不丢弃在它建立之后执行的命令所产生的效果。\n  \u003c/p\u003e\u003cp\u003e\n   指定一个尚未建立的保存点名称是一种错误。\n  \u003c/p\u003e\u003cp\u003e\n   就保存点而言，游标带有一些非事务性的行为。凡是在某个保存点内打开的游标，在回滚该保存点时都会被关闭。如果先前打开的游标在某个随后又被回滚的保存点内受到了\n   \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e 或 \u003ccode class=\"command\"\u003eMOVE\u003c/code\u003e 命令的影响，那么该游标会保留在 \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e 使其指向的位置上（也就是说，由 \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e 引起的游标移动不会被回滚）。关闭游标同样不会因回滚而撤销。不过，如果游标查询导致了其他副作用（例如该查询调用的易变函数带来的副作用），且这些副作用发生在后来被回滚的保存点期间，那么它们\u003cspan class=\"emphasis\"\u003e\u003cem\u003e会\u003c/em\u003e\u003c/span\u003e被回滚。如果某个游标的执行导致事务中止，该游标会进入不可执行状态，因此即使事务可以通过 \u003ccode class=\"command\"\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e 恢复，该游标也不能再使用。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e\n   要撤销在 \u003ccode class=\"literal\"\u003emy_savepoint\u003c/code\u003e 建立后执行的命令的效果：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nROLLBACK TO SAVEPOINT my_savepoint;\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   游标位置不受保存点回滚的影响：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nBEGIN;\n\nDECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;\n\nSAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        1\n\nROLLBACK TO SAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        2\n\nCOMMIT;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\n\u003cacronym class=\"acronym\"\u003eSQL\u003c/acronym\u003e 标准规定关键字 \u003ccode class=\"literal\"\u003eSAVEPOINT\u003c/code\u003e 是强制的，但\n   \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 和 \u003cspan class=\"productname\"\u003eOracle\u003c/span\u003e 允许省略它。SQL 只允许在 \u003ccode class=\"literal\"\u003eROLLBACK\u003c/code\u003e 之后使用 \u003ccode class=\"literal\"\u003eWORK\u003c/code\u003e 作为噪声词，不允许使用 \u003ccode class=\"literal\"\u003eTRANSACTION\u003c/code\u003e。此外，SQL 还有一个可选子句\n   \u003ccode class=\"literal\"\u003eAND [ NO ] CHAIN\u003c/code\u003e，而 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 当前尚不支持。除此之外，该命令符合 SQL 标准。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/zh/docs/18/sql-begin.html\" title=\"BEGIN\"\u003e\u003cspan class=\"refentrytitle\"\u003eBEGIN\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-commit.html\" title=\"COMMIT\"\u003e\u003cspan class=\"refentrytitle\"\u003eCOMMIT\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-release-savepoint.html\" title=\"RELEASE SAVEPOINT\"\u003e\u003cspan class=\"refentrytitle\"\u003eRELEASE SAVEPOINT\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-rollback.html\" title=\"ROLLBACK\"\u003e\u003cspan class=\"refentrytitle\"\u003eROLLBACK\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-savepoint.html\" title=\"SAVEPOINT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSAVEPOINT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","file":"sql-rollback-to.html","lang":"en","name":"ROLLBACK TO SAVEPOINT","purpose":"roll back to a savepoint","purpose_zh":"回滚到一个保存点","related":["begin","commit","release-savepoint","rollback","savepoint"],"sections":[{"html":"\u003cp\u003eRoll back all commands that were executed after the savepoint was established and then start a new subtransaction at the same transaction level. The savepoint remains valid and can be rolled back to again later, if needed.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e implicitly destroys all savepoints that were established after the named savepoint.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003esavepoint_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe savepoint to roll back to.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eUse \u003ca href=\"/docs/18/sql-release-savepoint.html\" title=\"RELEASE SAVEPOINT\"\u003e\u003ccode class=\"command\"\u003eRELEASE SAVEPOINT\u003c/code\u003e\u003c/a\u003e to destroy a savepoint without discarding the effects of commands executed after it was established.\u003c/p\u003e\u003cp\u003eSpecifying a savepoint name that has not been established is an error.\u003c/p\u003e\u003cp\u003eCursors have somewhat non-transactional behavior with respect to savepoints. Any cursor that is opened inside a savepoint will be closed when the savepoint is rolled back. If a previously opened cursor is affected by a \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e or \u003ccode class=\"command\"\u003eMOVE\u003c/code\u003e command inside a savepoint that is later rolled back, the cursor remains at the position that \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e left it pointing to (that is, the cursor motion caused by \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e is not rolled back). Closing a cursor is not undone by rolling back, either. However, other side-effects caused by the cursor's query (such as side-effects of volatile functions called by the query) \u003cspan class=\"emphasis\"\u003e\u003cem\u003eare\u003c/em\u003e\u003c/span\u003e rolled back if they occur during a savepoint that is later rolled back. A cursor whose execution causes a transaction to abort is put in a cannot-execute state, so while the transaction can be restored using \u003ccode class=\"command\"\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e, the cursor can no longer be used.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eTo undo the effects of the commands executed after \u003ccode class=\"literal\"\u003emy_savepoint\u003c/code\u003e was established:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eROLLBACK TO SAVEPOINT my_savepoint;\n\u003c/pre\u003e\u003cp\u003eCursor positions are not affected by savepoint rollback:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eBEGIN;\n\nDECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;\n\nSAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        1\n\nROLLBACK TO SAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        2\n\nCOMMIT;\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThe \u003cacronym\u003eSQL\u003c/acronym\u003e standard specifies that the key word \u003ccode class=\"literal\"\u003eSAVEPOINT\u003c/code\u003e is mandatory, but \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e and \u003cspan class=\"productname\"\u003eOracle\u003c/span\u003e allow it to be omitted. SQL allows only \u003ccode class=\"literal\"\u003eWORK\u003c/code\u003e, not \u003ccode class=\"literal\"\u003eTRANSACTION\u003c/code\u003e, as a noise word after \u003ccode class=\"literal\"\u003eROLLBACK\u003c/code\u003e. Also, SQL has an optional clause \u003ccode class=\"literal\"\u003eAND [ NO ] CHAIN\u003c/code\u003e which is not currently supported by \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e. Otherwise, this command conforms to the SQL standard.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/begin/?v=18\" title=\"BEGIN\"\u003e\u003cspan class=\"refentrytitle\"\u003eBEGIN\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/commit/?v=18\" title=\"COMMIT\"\u003e\u003cspan class=\"refentrytitle\"\u003eCOMMIT\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/release-savepoint/?v=18\" title=\"RELEASE SAVEPOINT\"\u003e\u003cspan class=\"refentrytitle\"\u003eRELEASE SAVEPOINT\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/rollback/?v=18\" title=\"ROLLBACK\"\u003e\u003cspan class=\"refentrytitle\"\u003eROLLBACK\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/savepoint/?v=18\" title=\"SAVEPOINT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSAVEPOINT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] \u003cem class=\"replaceable\"\u003e\u003ccode\u003esavepoint_name\u003c/code\u003e\u003c/em\u003e","synopsis_text":"ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/sql-rollback-to.html","sha256":"18834fc582c805a173ef1944190d1cecbad2bde716ad2a72f61f379c05529d2c"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-pgdoc"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"rollback-to-savepoint","SourceDatabase":"center","Version":"18","Locale":"en","Title":"ROLLBACK TO SAVEPOINT","Summary":"roll back to a savepoint","BodyHTML":"\u003cpre\u003eROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name\u003c/pre\u003e\u003csection\u003e\u003ch2\u003eDescription\u003c/h2\u003e\u003cp\u003eRoll back all commands that were executed after the savepoint was established and then start a new subtransaction at the same transaction level. The savepoint remains valid and can be rolled back to again later, if needed.\u003c/p\u003e\u003cp\u003e\u003ccode\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e implicitly destroys all savepoints that were established after the named savepoint.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eParameters\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003esavepoint_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe savepoint to roll back to.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eNotes\u003c/h2\u003e\u003cp\u003eUse \u003ca href=\"/docs/18/sql-release-savepoint.html\" title=\"RELEASE SAVEPOINT\" rel=\"nofollow\"\u003e\u003ccode\u003eRELEASE SAVEPOINT\u003c/code\u003e\u003c/a\u003e to destroy a savepoint without discarding the effects of commands executed after it was established.\u003c/p\u003e\u003cp\u003eSpecifying a savepoint name that has not been established is an error.\u003c/p\u003e\u003cp\u003eCursors have somewhat non-transactional behavior with respect to savepoints. Any cursor that is opened inside a savepoint will be closed when the savepoint is rolled back. If a previously opened cursor is affected by a \u003ccode\u003eFETCH\u003c/code\u003e or \u003ccode\u003eMOVE\u003c/code\u003e command inside a savepoint that is later rolled back, the cursor remains at the position that \u003ccode\u003eFETCH\u003c/code\u003e left it pointing to (that is, the cursor motion caused by \u003ccode\u003eFETCH\u003c/code\u003e is not rolled back). Closing a cursor is not undone by rolling back, either. However, other side-effects caused by the cursor\u0026#39;s query (such as side-effects of volatile functions called by the query) \u003cspan\u003e\u003cem\u003eare\u003c/em\u003e\u003c/span\u003e rolled back if they occur during a savepoint that is later rolled back. A cursor whose execution causes a transaction to abort is put in a cannot-execute state, so while the transaction can be restored using \u003ccode\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e, the cursor can no longer be used.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eExamples\u003c/h2\u003e\u003cp\u003eTo undo the effects of the commands executed after \u003ccode\u003emy_savepoint\u003c/code\u003e was established:\u003c/p\u003e\u003cpre\u003eROLLBACK TO SAVEPOINT my_savepoint;\n\u003c/pre\u003e\u003cp\u003eCursor positions are not affected by savepoint rollback:\u003c/p\u003e\u003cpre\u003eBEGIN;\n\nDECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;\n\nSAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        1\n\nROLLBACK TO SAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        2\n\nCOMMIT;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eCompatibility\u003c/h2\u003e\u003cp\u003eThe \u003cacronym\u003eSQL\u003c/acronym\u003e standard specifies that the key word \u003ccode\u003eSAVEPOINT\u003c/code\u003e is mandatory, but \u003cspan\u003ePostgreSQL\u003c/span\u003e and \u003cspan\u003eOracle\u003c/span\u003e allow it to be omitted. SQL allows only \u003ccode\u003eWORK\u003c/code\u003e, not \u003ccode\u003eTRANSACTION\u003c/code\u003e, as a noise word after \u003ccode\u003eROLLBACK\u003c/code\u003e. Also, SQL has an optional clause \u003ccode\u003eAND [ NO ] CHAIN\u003c/code\u003e which is not currently supported by \u003cspan\u003ePostgreSQL\u003c/span\u003e. Otherwise, this command conforms to the SQL standard.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/begin/?v=18\" title=\"BEGIN\" rel=\"nofollow\"\u003e\u003cspan\u003eBEGIN\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/commit/?v=18\" title=\"COMMIT\" rel=\"nofollow\"\u003e\u003cspan\u003eCOMMIT\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/release-savepoint/?v=18\" title=\"RELEASE SAVEPOINT\" rel=\"nofollow\"\u003e\u003cspan\u003eRELEASE SAVEPOINT\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/rollback/?v=18\" title=\"ROLLBACK\" rel=\"nofollow\"\u003e\u003cspan\u003eROLLBACK\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/savepoint/?v=18\" title=\"SAVEPOINT\" rel=\"nofollow\"\u003e\u003cspan\u003eSAVEPOINT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"wiki-repair-20261023:49de1065836d503ddc9101dd9e1239f3bce3875e5a35d82583167c3df8827bb6","ContentHash":"045f9fd129670bef92d00a34f22b271a77a58bc672b5315af1fdb8dae15b17ed","Payload":{"related":["begin","commit","release-savepoint","rollback","savepoint"],"sections":[{"html":"\u003cp\u003eRoll back all commands that were executed after the savepoint was established and then start a new subtransaction at the same transaction level. The savepoint remains valid and can be rolled back to again later, if needed.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e implicitly destroys all savepoints that were established after the named savepoint.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003esavepoint_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe savepoint to roll back to.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eUse \u003ca href=\"/docs/18/sql-release-savepoint.html\" title=\"RELEASE SAVEPOINT\"\u003e\u003ccode class=\"command\"\u003eRELEASE SAVEPOINT\u003c/code\u003e\u003c/a\u003e to destroy a savepoint without discarding the effects of commands executed after it was established.\u003c/p\u003e\u003cp\u003eSpecifying a savepoint name that has not been established is an error.\u003c/p\u003e\u003cp\u003eCursors have somewhat non-transactional behavior with respect to savepoints. Any cursor that is opened inside a savepoint will be closed when the savepoint is rolled back. If a previously opened cursor is affected by a \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e or \u003ccode class=\"command\"\u003eMOVE\u003c/code\u003e command inside a savepoint that is later rolled back, the cursor remains at the position that \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e left it pointing to (that is, the cursor motion caused by \u003ccode class=\"command\"\u003eFETCH\u003c/code\u003e is not rolled back). Closing a cursor is not undone by rolling back, either. However, other side-effects caused by the cursor's query (such as side-effects of volatile functions called by the query) \u003cspan class=\"emphasis\"\u003e\u003cem\u003eare\u003c/em\u003e\u003c/span\u003e rolled back if they occur during a savepoint that is later rolled back. A cursor whose execution causes a transaction to abort is put in a cannot-execute state, so while the transaction can be restored using \u003ccode class=\"command\"\u003eROLLBACK TO SAVEPOINT\u003c/code\u003e, the cursor can no longer be used.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eTo undo the effects of the commands executed after \u003ccode class=\"literal\"\u003emy_savepoint\u003c/code\u003e was established:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eROLLBACK TO SAVEPOINT my_savepoint;\n\u003c/pre\u003e\u003cp\u003eCursor positions are not affected by savepoint rollback:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eBEGIN;\n\nDECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;\n\nSAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        1\n\nROLLBACK TO SAVEPOINT foo;\n\nFETCH 1 FROM foo;\n ?column?\n----------\n        2\n\nCOMMIT;\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThe \u003cacronym\u003eSQL\u003c/acronym\u003e standard specifies that the key word \u003ccode class=\"literal\"\u003eSAVEPOINT\u003c/code\u003e is mandatory, but \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e and \u003cspan class=\"productname\"\u003eOracle\u003c/span\u003e allow it to be omitted. SQL allows only \u003ccode class=\"literal\"\u003eWORK\u003c/code\u003e, not \u003ccode class=\"literal\"\u003eTRANSACTION\u003c/code\u003e, as a noise word after \u003ccode class=\"literal\"\u003eROLLBACK\u003c/code\u003e. Also, SQL has an optional clause \u003ccode class=\"literal\"\u003eAND [ NO ] CHAIN\u003c/code\u003e which is not currently supported by \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e. Otherwise, this command conforms to the SQL standard.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/begin/?v=18\" title=\"BEGIN\"\u003e\u003cspan class=\"refentrytitle\"\u003eBEGIN\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/commit/?v=18\" title=\"COMMIT\"\u003e\u003cspan class=\"refentrytitle\"\u003eCOMMIT\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/release-savepoint/?v=18\" title=\"RELEASE SAVEPOINT\"\u003e\u003cspan class=\"refentrytitle\"\u003eRELEASE SAVEPOINT\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/rollback/?v=18\" title=\"ROLLBACK\"\u003e\u003cspan class=\"refentrytitle\"\u003eROLLBACK\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/savepoint/?v=18\" title=\"SAVEPOINT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSAVEPOINT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","synopsis_html":"ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] \u003cem class=\"replaceable\"\u003e\u003ccode\u003esavepoint_name\u003c/code\u003e\u003c/em\u003e","synopsis_text":"ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name"}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
