Declare savepoint

declare savepoint – declare a savepoint within the current transaction

  1. declare savepoint savepoint-name ;

Description

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.

Example

  1. # Will select no objects:
  2. select test::TestObject { name };
  3. start transaction;
  4. insert test::TestObject { name := 'q1' };
  5. insert test::TestObject { name := 'q2' };
  6. # Will select two TestObjects with names 'q1' and 'q2'
  7. select test::TestObject { name };
  8. declare savepoint f1;
  9. insert test::TestObject { name:='w1' };
  10. # Will select three TestObjects with names
  11. # 'q1' 'q2', and 'w1'
  12. select test::TestObject { name };
  13. rollback to savepoint f1;
  14. # Will select two TestObjects with names 'q1' and 'q2'
  15. select test::TestObject { name };
  16. rollback;

See also

Reference > EdgeQL > Start transaction

Reference > EdgeQL > Commit

Reference > EdgeQL > Rollabck

Reference > EdgeQL > Rollback to savepoint

Reference > EdgeQL > Release savepoint