Transactions 事务内部的过程调用

Transactions 事务内部的过程调用,transactions,procedure,postgresql-11,Transactions,Procedure,Postgresql 11,我有一个存储过程,它由表上的几个更新查询组成。它使用其他几个表中的数据。所以每个查询都在过程中提交,以释放查询中使用的表上的锁。 在某些时候,我需要用一些测试数据创建临时表。临时表的名称与永久表的名称相同,以隐藏永久表。我想使用oncommit-drop,但是,如果我开始事务临时表的创建,它会顺利进行,但是在调用我的\u very\u big\u过程时,我在事务的末尾出错,并指向过程内部的第一个commit 为了保持代码简短,我将使用一些虚拟示例: create or replace proce

我有一个存储过程,它由表上的几个更新查询组成。它使用其他几个表中的数据。所以每个查询都在过程中提交,以释放查询中使用的表上的锁。 在某些时候,我需要用一些测试数据创建临时表。临时表的名称与永久表的名称相同,以隐藏永久表。我想使用oncommit-drop,但是,如果我开始事务临时表的创建,它会顺利进行,但是在调用我的\u very\u big\u过程时,我在事务的末尾出错,并指向过程内部的第一个commit

为了保持代码简短,我将使用一些虚拟示例:

create or replace procedure my_very_big_procedure() as 
$$ 
begin
   insert into maintable select from table1, some_table, some_other_table;
   commit;

   update maintable using table1;
   commit;

   update maintable using table2;
   commit;
end;
$$ language pgplsql

begin
    create temp table maintable (like public.maintable) on commit drop;
    create temp table table1 (like public.table1) on commit drop -- works fine
    insert into table1 values %s  -- also works fine
    create temp table table2 (like public.table2) on commit drop -- again it's OK
    insert into table2 values %s -- and data's got inserted
    call my_very_big_procedure() -- and here comes an ERROR :(
    commit
end
那么,如何在事务块内使用过程调用呢

UPD: 嗯,似乎我必须在会话中创建临时表并手动删除它们。必须使用表oid来确保临时表存在。 我这样想:

select case when 'public.teblename'::regclass::oid = 'tablename'::regclass::oid then 'temp table exitsts' else 'no temp table - no drop' end.
那么,如何在事务块内使用过程调用呢

您不能,正如在以下文件中所述:

如果调用在事务块中执行,则被调用的过程 无法执行事务控制语句


问题中显示的语句序列无论如何都不起作用,因为该过程希望更新一个临时表,该临时表将在该更新的正上方被提交删除。

Daaamn,这很遗憾: