RELEASE SAVEPOINT statement commits the nested transaction starting at the corresponding SAVEPOINT statement using the same savepoint name, including all its nested sub-transactions. This is in addition to continued support for working with retry savepoints.
Synopsis
Required privileges
No privileges are required to release a savepoint. However, privileges are required for each statement within a transaction.Parameters
Handling errors
TheRELEASE SAVEPOINT statement is invalid after the nested transaction has encountered an error. After an error, the following statements can be used:
ROLLBACK TO SAVEPOINTto roll back to the previous savepoint.ROLLBACKorABORTto roll back the entire surrounding transaction.COMMITto commit the entire surrounding transaction. In case of error,COMMITis synonymous withROLLBACK/ABORTand also rolls back the entire transaction.
ROLLBACK TO SAVEPOINT and the statements in the transaction until the statements complete without error, then issue RELEASE.
To completely remove the marker of a nested transaction after it encounters an error and begin other work in the outer transaction, use ROLLBACK TO SAVEPOINT immediately followed by RELEASE.
Examples
Commit a nested transaction by releasing a savepoint
This example uses the MovR data set.
lower) and release (commit) the outer savepoint higher, which raises the promo code discount to 15% using CockroachDB’s JSONB functions.
Commit a transaction by releasing a retry savepoint
A savepoint defined with the namecockroach_restart is a “retry savepoint” and is used to implement advanced client-side transaction retries. For more information, see Retry savepoints.
After declaring a retry savepoint, commit the transaction with RELEASE SAVEPOINT and then prepare the connection for the next transaction with COMMIT:
SAVEPOINT for client-side transaction retries must also include functions to execute retries with ROLLBACK TO SAVEPOINT.
Note that you can customize the retry savepoint name to something other than cockroach_restart with a session variable if you need to.

