{
    "mode": "man",
    "parameter": "SAVEPOINT",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/SAVEPOINT/7/json",
    "generated": "2026-05-30T06:06:45Z",
    "synopsis": "SAVEPOINT savepointname",
    "sections": {
        "NAME": {
            "content": "SAVEPOINT - define a new savepoint within the current transaction\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "SAVEPOINT savepointname\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "SAVEPOINT establishes a new savepoint within the current transaction.\n\nA savepoint is a special mark inside a transaction that allows all commands that are executed\nafter it was established to be rolled back, restoring the transaction state to what it was at\nthe time of the savepoint.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "savepointname\nThe name to give to the new savepoint. If savepoints with the same name already exist,\nthey will be inaccessible until newer identically-named savepoints are released.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Use ROLLBACK TO to rollback to a savepoint. Use RELEASE SAVEPOINT to destroy a savepoint,\nkeeping the effects of commands executed after it was established.\n\nSavepoints can only be established when inside a transaction block. There can be multiple\nsavepoints defined within a transaction.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To establish a savepoint and later undo the effects of all commands executed after it was\nestablished:\n\nBEGIN;\nINSERT INTO table1 VALUES (1);\nSAVEPOINT mysavepoint;\nINSERT INTO table1 VALUES (2);\nROLLBACK TO SAVEPOINT mysavepoint;\nINSERT INTO table1 VALUES (3);\nCOMMIT;\n\nThe above transaction will insert the values 1 and 3, but not 2.\n\nTo establish and later destroy a savepoint:\n\nBEGIN;\nINSERT INTO table1 VALUES (3);\nSAVEPOINT mysavepoint;\nINSERT INTO table1 VALUES (4);\nRELEASE SAVEPOINT mysavepoint;\nCOMMIT;\n\nThe above transaction will insert both 3 and 4.\n\nTo use a single savepoint name:\n\nBEGIN;\nINSERT INTO table1 VALUES (1);\nSAVEPOINT mysavepoint;\nINSERT INTO table1 VALUES (2);\nSAVEPOINT mysavepoint;\nINSERT INTO table1 VALUES (3);\n\n-- rollback to the second savepoint\nROLLBACK TO SAVEPOINT mysavepoint;\nSELECT * FROM table1;               -- shows rows 1 and 2\n\n-- release the second savepoint\nRELEASE SAVEPOINT mysavepoint;\n\n-- rollback to the first savepoint\nROLLBACK TO SAVEPOINT mysavepoint;\nSELECT * FROM table1;               -- shows only row 1\nCOMMIT;\n\nThe above transaction shows row 3 being rolled back first, then row 2.\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "SQL requires a savepoint to be destroyed automatically when another savepoint with the same\nname is established. In PostgreSQL, the old savepoint is kept, though only the more recent\none will be used when rolling back or releasing. (Releasing the newer savepoint with RELEASE\nSAVEPOINT will cause the older one to again become accessible to ROLLBACK TO SAVEPOINT and\nRELEASE SAVEPOINT.) Otherwise, SAVEPOINT is fully SQL conforming.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "BEGIN(7), COMMIT(7), RELEASE SAVEPOINT (RELEASESAVEPOINT(7)), ROLLBACK(7), ROLLBACK TO\nSAVEPOINT (ROLLBACKTOSAVEPOINT(7))\n\n\n\nPostgreSQL 14.23                                2026                                    SAVEPOINT(7)",
            "subsections": []
        }
    },
    "summary": "SAVEPOINT - define a new savepoint within the current transaction",
    "flags": [],
    "examples": [
        "To establish a savepoint and later undo the effects of all commands executed after it was",
        "established:",
        "BEGIN;",
        "INSERT INTO table1 VALUES (1);",
        "SAVEPOINT mysavepoint;",
        "INSERT INTO table1 VALUES (2);",
        "ROLLBACK TO SAVEPOINT mysavepoint;",
        "INSERT INTO table1 VALUES (3);",
        "COMMIT;",
        "The above transaction will insert the values 1 and 3, but not 2.",
        "To establish and later destroy a savepoint:",
        "BEGIN;",
        "INSERT INTO table1 VALUES (3);",
        "SAVEPOINT mysavepoint;",
        "INSERT INTO table1 VALUES (4);",
        "RELEASE SAVEPOINT mysavepoint;",
        "COMMIT;",
        "The above transaction will insert both 3 and 4.",
        "To use a single savepoint name:",
        "BEGIN;",
        "INSERT INTO table1 VALUES (1);",
        "SAVEPOINT mysavepoint;",
        "INSERT INTO table1 VALUES (2);",
        "SAVEPOINT mysavepoint;",
        "INSERT INTO table1 VALUES (3);",
        "-- rollback to the second savepoint",
        "ROLLBACK TO SAVEPOINT mysavepoint;",
        "SELECT * FROM table1;               -- shows rows 1 and 2",
        "-- release the second savepoint",
        "RELEASE SAVEPOINT mysavepoint;",
        "-- rollback to the first savepoint",
        "ROLLBACK TO SAVEPOINT mysavepoint;",
        "SELECT * FROM table1;               -- shows only row 1",
        "COMMIT;",
        "The above transaction shows row 3 being rolled back first, then row 2."
    ],
    "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": "ROLLBACKTOSAVEPOINT",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ROLLBACKTOSAVEPOINT/7/json"
        }
    ]
}