VastbaseE100

基于开源技术的HTAP数据库管理系统。性能优异,稳定可靠,提供诸多专属领域特性。

Menu

自治事务控制

create table at_tb2(id int, name text);
CREATE PROCEDURE at_test3(int)
as $$  
declare
PRAGMA autonomous_transaction;
BEGIN
        insert into at_tb2 values(1,'before s1');
        insert into at_tb2 values(2,'after s1');
        if $1 > 10 then
                ROLLBACK;
        else
                COMMIT;
        end if;
end;
$$ LANGUAGE plpgsql;   

CREATE or replace PROCEDURE at_test4(int)
as $$  
declare
begin
   insert into at_tb2 values(3,'atlasdb');
   call at_test3(1);
   insert into at_tb2 values(4,'atlasdb');
   rollback;
end;
$$ LANGUAGE plpgsql;  

call at_test4(1);
atlasdb=# select * from at_tb2;
 id |   name    
----+-----------
  1 | before s1
  2 | after s1
(2 rows)