SAVEPOINT

On this page Carat arrow pointing down
Warning:
CockroachDB v2.1 is no longer supported as of April 30, 2020. For more details, refer to the Release Support Policy.

The SAVEPOINT cockroach_restart statement defines the intent to retry transactions using the CockroachDB-provided function for client-side transaction retries. For more information, see Transaction Retries.

Warning:
CockroachDB’s SAVEPOINT implementation only supports the cockroach_restart savepoint and does not support all savepoint functionality, such as nested transactions.

Synopsis

SAVEPOINT name

Required privileges

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

Example

After you BEGIN the transaction, you must create the savepoint to identify that if the transaction contends with another transaction for resources and "loses", you intend to use the function for client-side transaction retries:

icon/buttons/copy
> BEGIN;
icon/buttons/copy
> SAVEPOINT cockroach_restart;
icon/buttons/copy
> UPDATE products SET inventory = 0 WHERE sku = '8675309';
icon/buttons/copy
> INSERT INTO orders (customer, sku, status) VALUES (1001, '8675309', 'new');
icon/buttons/copy
> RELEASE SAVEPOINT cockroach_restart;
icon/buttons/copy
> COMMIT;

When using SAVEPOINT, an application must also include functions to execute retries with ROLLBACK TO SAVEPOINT cockroach_restart.

See also


Yes No
On this page

Yes No