{
    "content": [
        {
            "type": "text",
            "text": "# ROLLBACK_TO_SAVEPOINT(7) (man)\n\n**Summary:** ROLLBACKTOSAVEPOINT - roll back to a savepoint\n\n**Synopsis:** ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepointname\n\n## Examples\n\n- `To undo the effects of the commands executed after mysavepoint was established:`\n- `ROLLBACK TO SAVEPOINT mysavepoint;`\n- `Cursor positions are not affected by savepoint rollback:`\n- `BEGIN;`\n- `DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;`\n- `SAVEPOINT foo;`\n- `FETCH 1 FROM foo;`\n- `?column?`\n- `----------`\n- `ROLLBACK TO SAVEPOINT foo;`\n- `FETCH 1 FROM foo;`\n- `?column?`\n- `----------`\n- `COMMIT;`\n\n## See Also\n\n- BEGIN(7)\n- COMMIT(7)\n- RELEASESAVEPOINT(7)\n- ROLLBACK(7)\n- SAVEPOINT(7)\n- SAVEPOINT(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (2 lines)\n- **DESCRIPTION** (6 lines)\n- **PARAMETERS** (3 lines)\n- **NOTES** (16 lines)\n- **EXAMPLES** (26 lines)\n- **COMPATIBILITY** (5 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nROLLBACKTOSAVEPOINT - roll back to a savepoint\n\n### SYNOPSIS\n\nROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepointname\n\n### DESCRIPTION\n\nRoll back all commands that were executed after the savepoint was established. The savepoint\nremains valid and can be rolled back to again later, if needed.\n\nROLLBACK TO SAVEPOINT implicitly destroys all savepoints that were established after the\nnamed savepoint.\n\n### PARAMETERS\n\nsavepointname\nThe savepoint to roll back to.\n\n### NOTES\n\nUse RELEASE SAVEPOINT to destroy a savepoint without discarding the effects of commands\nexecuted after it was established.\n\nSpecifying a savepoint name that has not been established is an error.\n\nCursors have somewhat non-transactional behavior with respect to savepoints. Any cursor that\nis opened inside a savepoint will be closed when the savepoint is rolled back. If a\npreviously opened cursor is affected by a FETCH or MOVE command inside a savepoint that is\nlater rolled back, the cursor remains at the position that FETCH left it pointing to (that\nis, the cursor motion caused by FETCH is not rolled back). Closing a cursor is not undone by\nrolling back, either. However, other side-effects caused by the cursor's query (such as\nside-effects of volatile functions called by the query) are rolled back if they occur during\na savepoint that is later rolled back. A cursor whose execution causes a transaction to abort\nis put in a cannot-execute state, so while the transaction can be restored using ROLLBACK TO\nSAVEPOINT, the cursor can no longer be used.\n\n### EXAMPLES\n\nTo undo the effects of the commands executed after mysavepoint was established:\n\nROLLBACK TO SAVEPOINT mysavepoint;\n\nCursor positions are not affected by savepoint rollback:\n\nBEGIN;\n\nDECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;\n\nSAVEPOINT foo;\n\nFETCH 1 FROM foo;\n?column?\n----------\n1\n\nROLLBACK TO SAVEPOINT foo;\n\nFETCH 1 FROM foo;\n?column?\n----------\n2\n\nCOMMIT;\n\n### COMPATIBILITY\n\nThe SQL standard specifies that the key word SAVEPOINT is mandatory, but PostgreSQL and\nOracle allow it to be omitted. SQL allows only WORK, not TRANSACTION, as a noise word after\nROLLBACK. Also, SQL has an optional clause AND [ NO ] CHAIN which is not currently supported\nby PostgreSQL. Otherwise, this command conforms to the SQL standard.\n\n### SEE ALSO\n\nBEGIN(7), COMMIT(7), RELEASE SAVEPOINT (RELEASESAVEPOINT(7)), ROLLBACK(7), SAVEPOINT(7)\n\n\n\nPostgreSQL 14.23                                2026                        ROLLBACK TO SAVEPOINT(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "ROLLBACK_TO_SAVEPOINT",
        "section": "7",
        "mode": "man",
        "summary": "ROLLBACKTOSAVEPOINT - roll back to a savepoint",
        "synopsis": "ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepointname",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "To undo the effects of the commands executed after mysavepoint was established:",
            "ROLLBACK TO SAVEPOINT mysavepoint;",
            "Cursor positions are not affected by savepoint rollback:",
            "BEGIN;",
            "DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;",
            "SAVEPOINT foo;",
            "FETCH 1 FROM foo;",
            "?column?",
            "----------",
            "ROLLBACK TO SAVEPOINT foo;",
            "FETCH 1 FROM foo;",
            "?column?",
            "----------",
            "COMMIT;"
        ],
        "see_also": [
            {
                "name": "BEGIN",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/BEGIN/7/json"
            },
            {
                "name": "COMMIT",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/COMMIT/7/json"
            },
            {
                "name": "RELEASESAVEPOINT",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/RELEASESAVEPOINT/7/json"
            },
            {
                "name": "ROLLBACK",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ROLLBACK/7/json"
            },
            {
                "name": "SAVEPOINT",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/SAVEPOINT/7/json"
            },
            {
                "name": "SAVEPOINT",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/SAVEPOINT/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}