SAVEPOINT cockroach_restart 语句目的是使用 CockroachDB-provided函数重试transactions 。更多的信息请看Transaction Retries.

Warning: CockroachDB的SAVEPOINT 仅支持cockroach_restartsavepoint,不支持其他savepoint功能,例如嵌套事务。

概要

图片

所需权限

创建一个savepoint不需要权限 。但是,事务中每条语句的操作权限是需要的。

例子

创建Savepoint

BEGIN 事务后,必须创建savepoint,表明在与其他事务发生资源争用并且获取资源失败后,需要使用 the function for client-side transaction retries.

> 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;

当使用SAVEPOINT时,你的应用必须有包含ROLLBACK TO SAVEPOINT cockroach_restart执行重试的函数。

See Also