PostgreSQL 事务控制
在我们做PG迁移的时候,用AWS工具经常会遇到这样的提示“Transactioncontrol is only possible from the top level or nested callinvocations without any other intervening command”
在点一下具体的问题,如上图所示,发现是commit的问题。
这里我写了一个存储过程,用python程序调用来测试了一下这个问题。
1.首先创建一个表
create tabletest(a1,a2) as select 1 n,current_timestamp t;
2.接下来创建一个存储过程
create or replaceprocedure test_insert(a1 int, a2 int) as
$$
begin
for i in a1..a2loop
insert into testvalues (i,current_timestamp);
commit;
end loop;
end;
$$ language plpgsql;
3.在命令行执行调用