COMMIT

On this page Carat arrow pointing down
Warning:
As of May 10, 2022, CockroachDB v20.2 is no longer supported. For more details, refer to the Release Support Policy.

The COMMIT statement commits the current transaction or, when using advanced client-side transaction retries, clears the connection to allow new transactions to begin.

When using advanced client-side transaction retries, statements issued after SAVEPOINT are committed when RELEASE SAVEPOINT is issued instead of COMMIT. However, you must still issue a COMMIT statement to clear the connection for the next transaction.

For non-retryable transactions, if statements in the transaction generated any errors, COMMIT is equivalent to ROLLBACK, which aborts the transaction and discards all updates made by its statements.

Synopsis

COMMIT END TRANSACTION
## Required privileges No [privileges](authorization.html#assign-privileges) are required to commit a transaction. However, privileges are required for each statement within a transaction. ## Aliases In CockroachDB, `END` is an alias for the `COMMIT` statement. ## Example ### Commit a transaction How you commit transactions depends on how your application handles [transaction retries](transactions.html#transaction-retries). #### Client-side retryable transactions When using [advanced client-side transaction retries](advanced-client-side-transaction-retries.html), statements are committed by [`RELEASE SAVEPOINT`](release-savepoint.html). `COMMIT` itself only clears the connection for the next transaction.
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;
Warning:
This example assumes you're using client-side intervention to handle transaction retries.

Automatically retried transactions

If you are using transactions that CockroachDB will automatically retry (i.e., all statements sent in a single batch), commit the transaction with COMMIT.

icon/buttons/copy
> BEGIN; UPDATE products SET inventory = 100 WHERE = '8675309'; UPDATE products SET inventory = 100 WHERE = '8675310'; COMMIT;

See also


Yes No
On this page

Yes No