释放保存点

用于删除先前保存点的 SQL 命令

RELEASE SAVEPOINT 是一个事务命令,用于删除之前定义的 savepoint

RELEASE SAVEPOINTPostgreSQL 8.0 中添加。

用法

RELEASE SAVEPOINT 删除在事务期间先前定义的保存点。如果在已释放的保存点之后还有其他保存点,则这些保存点也将被释放。

更改历史记录

示例

RELEASE SAVEPOINT 的基本执行示例

postgres=# BEGIN;
BEGIN

postgres=*# INSERT INTO foo VALUES(1);
INSERT 0 1

postgres=*# SAVEPOINT s1;
SAVEPOINT

postgres=*# INSERT INTO foo VALUES(2);
INSERT 0 1

postgres=*# SAVEPOINT s2;
SAVEPOINT

postgres=*# INSERT INTO foo VALUES(3);
INSERT 0 1

postgres=*# RELEASE SAVEPOINT s2;
RELEASE

此时,只能回滚到保存点 s1,或回滚整个事务

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

postgres=!# ROLLBACK TO SAVEPOINT s1;
ROLLBACK

如果在已释放的保存点之后存在保存点,则这些保存点也将被释放

postgres=# BEGIN;
BEGIN

postgres=*# INSERT INTO foo VALUES(1);
INSERT 0 1

postgres=*# SAVEPOINT s1;
SAVEPOINT

postgres=*# INSERT INTO foo VALUES(2);
INSERT 0 1

postgres=*# SAVEPOINT s2;
SAVEPOINT

postgres=*# RELEASE SAVEPOINT s1;
RELEASE

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

分类

SQL 命令事务命令事务

另请参阅

SAVEPOINTROLLBACK TO SAVEPOINT

反馈

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