RELEASE SAVEPOINT

On this page Carat arrow pointing down

When using advanced client-side transaction retries, the RELEASE SAVEPOINT statement commits the transaction.

If statements in the transaction generated any non-retry errors, RELEASE SAVEPOINT is equivalent to ROLLBACK, which aborts the transaction and discards all updates made by its statements.

Note that although issuing this statement commits the transaction, you must also issue a subsequent COMMIT statement to prepare the connection for the next transaction.

Warning:

CockroachDB's SAVEPOINT implementation does not support nested transactions (i.e., subtransactions). It is only used to handle transaction retries.

Synopsis

RELEASE SAVEPOINT name

Required privileges

No privileges are required to release a savepoint. However, privileges are required for each statement within a transaction.

Parameters

Parameter Description
name The name of the savepoint. Defaults to cockroach_restart, but may be customized. For more information, see Customizing the savepoint name.

Customizing the savepoint name

Set the force_savepoint_restart session variable to true to enable using a custom name for the restart savepoint (for example, because you are using an ORM that wants to use its own names for savepoints).

Once this variable is set, the SAVEPOINT statement will accept any name for the savepoint, not just cockroach_restart. This allows compatibility with existing code that uses a single savepoint per transaction as long as that savepoint occurs before any statements that access data stored in non-virtual tables.

Warning:

The force_savepoint_restart variable changes the semantics of CockroachDB savepoints so that RELEASE SAVEPOINT <your-custom-name> functions as a real commit. Note that the existence of this variable and its behavior does not change the fact that CockroachDB savepoints can only be used as a part of the transaction retry protocol.

Examples

Commit a Transaction

After declaring a SAVEPOINT, commit the transaction with RELEASE SAVEPOINT and then prepare the connection for the next transaction with COMMIT:

icon/buttons/copy
> BEGIN;

> SAVEPOINT cockroach_restart;

> UPDATE products SET inventory = 0 WHERE sku = '8675309';

> INSERT INTO orders (customer, sku, status) VALUES (1001, '8675309', 'new');

> RELEASE SAVEPOINT cockroach_restart;

> COMMIT;
Warning:
This example assumes you're using client-side intervention to handle transaction retries.

See also


Yes No
On this page

Yes No