> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RELEASE SAVEPOINT

The `RELEASE SAVEPOINT` statement commits the [nested transaction](/docs/stable/transactions.md#nested-transactions) 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](/docs/stable/savepoint.md#savepoints-for-client-side-transaction-retries).

## Synopsis

![release\_savepoint syntax diagram](https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/release_savepoint.svg?fit=max\&auto=format\&n=UZNSFbmU2EwEm6G5\&q=85\&s=3beaf2bc277186ca3cefab70f41c32e4)

## Required privileges

No [privileges](/docs/stable/security-reference/authorization.md#managing-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.  [Retry savepoints](/docs/stable/savepoint.md#savepoints-for-client-side-transaction-retries) default to using the name `cockroach_restart`, but this can be customized using a session variable.  For more information, see [Customizing the retry savepoint name](/docs/stable/savepoint.md#customizing-the-retry-savepoint-name). |

## Handling errors

The `RELEASE SAVEPOINT` statement is invalid after the nested transaction has encountered an error. After an error, the following statements can be used:

* [`ROLLBACK TO SAVEPOINT`](/docs/stable/rollback-transaction#rollback-a-nested-transaction) to roll back to the previous savepoint.
* [`ROLLBACK` or `ABORT`](/docs/stable/rollback-transaction#rollback-a-transaction) to roll back the entire surrounding transaction.
* [`COMMIT`](/docs/stable/commit-transaction) to commit the entire surrounding transaction. In case of error, `COMMIT` is synonymous with [`ROLLBACK`/`ABORT`](/docs/stable/rollback-transaction) and also rolls back the entire transaction.

When a (sub-)transaction encounters a retry error, the client should repeat `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`](/docs/stable/rollback-transaction#rollback-a-nested-transaction) immediately followed by `RELEASE`.

## Examples

### Commit a nested transaction by releasing a savepoint

> [!NOTE]
>
> This example uses the [MovR data set](/docs/stable/movr.md).

In the example below, we roll back the inner [nested transaction](/docs/stable/transactions.md#nested-transactions) (marked by the savepoint `lower`) and release (commit) the outer savepoint `higher`, which raises the promo code discount to 15% using CockroachDB's [JSONB functions](/docs/stable/jsonb.md#functions).

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> BEGIN;
SAVEPOINT higher;
UPDATE promo_codes SET rules = jsonb_set(rules, '{value}', '"15%"') WHERE rules @> '{"type": "percent_discount"}';
SAVEPOINT lower;
UPDATE promo_codes SET rules = jsonb_set(rules, '{value}', '"7.5%"') WHERE rules @> '{"type": "percent_discount"}';
ROLLBACK TO SAVEPOINT lower;
RELEASE SAVEPOINT higher;
COMMIT;
```

```
COMMIT
```

### Commit a transaction by releasing a retry savepoint

A savepoint defined with the name `cockroach_restart` is a "retry savepoint" and is used to implement [advanced client-side transaction retries](/docs/stable/advanced-client-side-transaction-retries.md). For more information, see [Retry savepoints](/docs/stable/advanced-client-side-transaction-retries.md#retry-savepoints).

After declaring a retry savepoint, commit the transaction with `RELEASE SAVEPOINT` and then prepare the connection for the next transaction with [`COMMIT`](/docs/stable/commit-transaction):

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> 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;
```

Applications using `SAVEPOINT` for client-side transaction retries must also include functions to execute retries with [`ROLLBACK TO SAVEPOINT `](/docs/stable/rollback-transaction#retry-a-transaction).

Note that you can [customize the retry savepoint name](/docs/stable/savepoint.md#customizing-the-retry-savepoint-name) to something other than `cockroach_restart` with a session variable if you need to.

## See also

* [Transactions](/docs/stable/transactions.md)
* [`SAVEPOINT`](/docs/stable/savepoint)
* [`SHOW SAVEPOINT STATUS`](/docs/stable/show-savepoint-status)
* [`ROLLBACK`](/docs/stable/rollback-transaction)
* [`BEGIN`](/docs/stable/begin-transaction)
* [`COMMIT`](/docs/stable/commit-transaction)
