簡體   English   中英

用於遍歷臨時表

[英]For loop through temporary table

我在function(postgresql)有一個臨時表function(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 loop此臨時表以使用breakup_id更新amount列。 如何在postgresql function做到這一點?

如果您對金額有復雜的邏輯,請使用

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 = /*simple value*/ where id=..

最后-請記住,臨時表並不意味着保留數據-例如,您將無法從其他后端讀取數據...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM