RELEASE SAVEPOINT
是一个事务命令,用于删除之前定义的 savepoint
。
RELEASE SAVEPOINT
在 PostgreSQL 8.0 中添加。
用法
RELEASE SAVEPOINT
删除在事务期间先前定义的保存点。如果在已释放的保存点之后还有其他保存点,则这些保存点也将被释放。
更改历史记录
- PostgreSQL 8.0
- 添加(初始提交 cc813fc2)
示例
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
参考文献
- PostgreSQL 文档: RELEASE SAVEPOINT