Reputation: 354
i have a temporary table in a 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;
I need to for loop
this temporary table to update amount
column using breakup_id
. How to do that in postgresql function
?
Upvotes: 2
Views: 4696
Reputation: 51456
if you have some complicated logic for value of amount, use
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;
$$
;
Otherwise use UPDATE temp_table set amount = /*simple value*/ where id=..
And lastly - remember that temporary table is not meant to keep data - Eg you wont be able to read data from it with other backend...
Upvotes: 5