Start transaction

start transaction – start a transaction

  1. start transaction transaction-mode [ , ... ] ;
  2. where transaction-mode is one of:
  3. isolation serializable
  4. read write | read only
  5. deferrable | not deferrable

Description

This command starts a new transaction block.

Any EdgeDB command outside of an explicit transaction block starts an implicit transaction block; the transaction is then automatically committed if the command was executed successfully, or automatically rollbacked if there was an error. This behaviour is often called “autocommit”.

Parameters

The transaction-mode can be one of the following:

isolation serializable

All statements of the current transaction can only see data changes committed before the first query or data-modification statement was executed in this transaction. If a pattern of reads and writes among concurrent serializable transactions would create a situation which could not have occurred for any serial (one-at-a-time) execution of those transactions, one of them will be rolled back with a serialization_failure error.

read write

Sets the transaction access mode to read/write.

This is the default.

read only

Sets the transaction access mode to read-only. Any data modifications with insert, update, or delete are disallowed. Schema mutations via DDL are also disallowed.

deferrable

The transaction can be set to deferrable mode only when it is serializable and read only. When all three of these properties are selected for a transaction, the transaction may block when first acquiring its snapshot, after which it is able to run without the normal overhead of a serializable transaction and without any risk of contributing to or being canceled by a serialization failure. This mode is well suited for long-running reports or backups.

Examples

Start a new transaction and rollback it:

  1. start transaction;
  2. select 'Hello World!';
  3. rollback;

Start a serializable deferrable transaction:

  1. start transaction isolation serializable, read only, deferrable;

See also

Reference > EdgeQL > Commit

Reference > EdgeQL > Rollback

Reference > EdgeQL > Declare savepoint

Reference > EdgeQL > Rollback to savepoint

Reference > EdgeQL > Release savepoint