commit/rollback
在plpgsql定义存储过程中,增加两条指令:commit和rollback。来控制对当前子事务的提交或是回滚。
示例
vastbase=# create table test_pro(id int,a text,c char(20));
CREATE TABLE
vastbase=# create or replace procedure test_pro1 is
vastbase$# begin
vastbase$# insert into test_pro values(1,'b1','c1');
vastbase$# commit;
vastbase$# insert into test_pro values(2,'b2','b3');
vastbase$# insert into test_pro values(3,'b3','b3');
vastbase$# insert into test_pro values(4,'b4','b4');
vastbase$# insert into test_pro values(5,'b5','b3');
vastbase$# insert into test_pro values(6,'b6','b6');
vastbase$# commit;
vastbase$# delete from test_pro where id =2;
vastbase$# rollback;
vastbase$# delete from test_pro where id =2;
vastbase$# commit;
vastbase$# end;
vastbase$# /
CREATE PROCEDURE
vastbase=# call test_pro1();
test_pro1
-------------
(一行记录)
vastbase=# select * from test_pro;