我有查询。我需要在底部查询中获取select的值。但我不能做提交后的事务。我怎样才能得到它?
start transaction;
with table as
(
select id, type, status
from new_rows
where status = 'new'
),
insert_table as
(
insert into copy_table(type, status)
select type, status
from table
returning id, type
),
del_table as
(
delete
from new_rows
where id in (select id from table)
returning id, type
)
select 'insert', *
from insert_table
union
select 'delete', *
from del_table
order by 2;
commit transaction;
我准备了很多关于stackoverflow的问题(我认为这是最合适的,但我不能在我的情况下应用这个解决方案如何在交易中获得SELECT语句的结果?(,一个尝试阅读的postgres文档,иΓе我找不到我的问题的答案。我将感谢任何信息,请
两个想法:
-
将结果存储在临时表中,并在提交后返回其内容。
-
将查询结果存储在
jsonb
变量中(使用to_jsonb
和jsonb_agg
(,并在提交后提取结果。