我在函数(postgresql)
中有一个临时表
create temporary table temp_table (
id serial
,breakup_id integer
,enquiry_id integer
,estimate_id integer
,customer_name CHARACTER VARYING
,month integer
,year integer
,amount numeric
) on commit drop;
我需要for循环
这个临时表来使用breakup_id
更新amount
列。如何在postgresql函数
中做到这一点?
最佳答案
如果您对金额值有一些复杂的逻辑,请使用
do
$$
declare _r record;
begin
for _r in (select * from temp_table) loop
update temp_table set amount='complicated calculated values' where id = _r.id;
end loop;
end;
$$
;
否则使用UPDATE temp_table set amount =/*简单值*/where id=..
最后 - 请记住临时表并不意味着保存数据 - 例如,您将无法使用其他后端从中读取数据......
关于sql - For循环遍历临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41954473/