ROLLBACK TO SAVEPOINT

用于将事务回滚到先前保存点的 SQL 命令

ROLLBACK TO SAVEPOINT 是一个事务命令,用于将事务回滚到之前定义的 savepoint

ROLLBACK TO SAVEPOINT 添加于 PostgreSQL 8.0

更改历史记录

示例

ROLLBACK TO SAVEPOINT 的基本用法

postgres=# BEGIN;
BEGIN

postgres=*# SELECT 1;
 ?column?
----------
        1
(1 row)

postgres=*# SAVEPOINT s1;
SAVEPOINT

postgres=*# SELECT foo;
ERROR:  column "foo" does not exist
LINE 1: SELECT foo;
               ^

postgres=!# ROLLBACK TO SAVEPOINT s1;
ROLLBACK

postgres=*# SELECT 2;
 ?column?
----------
        2
(1 row)

postgres=*# COMMIT;
COMMIT

可以多次回滚到同一个保存点

postgres=*# SAVEPOINT s1;
SAVEPOINT

postgres=*# ROLLBACK TO SAVEPOINT s1;
ROLLBACK

postgres=*# ROLLBACK TO SAVEPOINT s1;
ROLLBACK

无法回滚到之前已释放的保存点

postgres=*# RELEASE SAVEPOINT s1;
RELEASE

postgres=*# ROLLBACK TO SAVEPOINT s1;
ERROR:  savepoint "s1" does not exist

尝试回滚到不存在的保存点

postgres=*# ROLLBACK TO SAVEPOINT foo;
ERROR:  savepoint "foo" does not exist

分类

SQL 命令事务命令事务

另请参阅

SAVEPOINTRELEASE SAVEPOINT

反馈

提交任何关于“ROLLBACK TO SAVEPOINT”的评论、建议或更正 此处