Start transaction
start transaction
– start a transaction
start transaction transaction-mode [ , ... ] ;
where transaction-mode is one of:
isolation serializable
read write | read only
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 behavior is often called “autocommit”.
Parameters
The transaction-mode can be one of the following:
- isolation serializable
-
All statements in the current transaction can only see data changes that were committed before the first query or data modification statement was executed within this transaction. If a pattern of reads and writes among concurrent serializable transactions creates a situation that could not have occurred in 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
, ordelete
are disallowed. Schema mutations via DDL are also disallowed. - deferrable
-
The transaction can be set to deferrable mode only when it is
serializable
andread 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 aserializable
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:
start transaction;
select 'Hello World!';
rollback;
Start a serializable deferrable transaction:
start transaction isolation serializable, read only, deferrable;