DECLARE SAVEPOINT

DECLARE SAVEPOINT – declare a savepoint within the current transaction

DECLARE SAVEPOINT savepoint-name ;

SAVEPOINT establishes a new savepoint within the current transaction.

A savepoint is a special mark inside a transaction that allows all commands that are executed after it was established to be rolled back, restoring the transaction state to what it was at the time of the savepoint.

It is an error to declare a savepoint outside of a transaction.

Copy
# Will select no objects:
SELECT test::TestObject { name };

START TRANSACTION;

    INSERT test::TestObject { name := 'q1' };
    INSERT test::TestObject { name := 'q2' };

    # Will select two TestObjects with names 'q1' and 'q2'
    SELECT test::TestObject { name };

    DECLARE SAVEPOINT f1;
        INSERT test::TestObject { name:='w1' };

        # Will select three TestObjects with names
        # 'q1' 'q2', and 'w1'
        SELECT test::TestObject { name };
    ROLLBACK TO SAVEPOINT f1;

    # Will select two TestObjects with names 'q1' and 'q2'
    SELECT test::TestObject { name };

ROLLBACK;
Light
Dark
System