Light
Dark
System
v4latest
v5dev
v4latest
v3
v2
v1

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

We use ChatGPT with additional context from our documentation to answer your questions. Not all answers will be accurate. Please join our Discord if you need more help.