Sql For循环通过临时表

Sql For循环通过临时表,sql,postgresql,plpgsql,Sql,Postgresql,Plpgsql,我在函数(postgresql) 我需要for loop这个临时表来使用breakup\u id更新amount列。如何在postgresql函数中执行此操作?如果您对金额的值有一些复杂的逻辑,请使用 do $$ declare _r record; begin for _r in (select * from temp_table) loop update temp_table set amount='complicated calculated values' wher

我在
函数(postgresql)


我需要
for loop
这个临时表来使用
breakup\u 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; 
$$
;
否则使用
updatetemp\u表集合金额=/*简单值*/其中id=…


最后-记住临时表并不是用来保存数据的-例如,您将无法使用其他后端从中读取数据

如果您对金额的值有一些复杂的逻辑,请使用

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; 
$$
;
否则使用
updatetemp\u表集合金额=/*简单值*/其中id=…


最后-记住临时表并不是用来保存数据的-例如,您将无法使用其他后端从中读取数据

请参阅。您已经有了一个函数?删除无关的标记为什么是循环?一个简单的
updateset amount=42,其中(1,2,3)
中的breakup_id就可以了。@laurez Albe thqSee.你已经有一个函数了,为什么要删除一个循环?一个简单的
更新集amount=42,其中(1,2,3)
中的分解id就可以了。@Laurenz-Albe-thq