Skip to content

Instantly share code, notes, and snippets.

@claudiobusatto
Created September 15, 2021 12:20
Show Gist options
  • Save claudiobusatto/21e3dad8fef6f40cf2a9fd8287199816 to your computer and use it in GitHub Desktop.
Save claudiobusatto/21e3dad8fef6f40cf2a9fd8287199816 to your computer and use it in GitHub Desktop.
Template of an update using a for loop in plpgsql
do $$
declare
data_values record;
begin
for data_values in (select * from table)
loop
update table
set column_value = (select column_value from another_table where id = data_values.id)
where id = data_values.id;
end loop;
end;
$$ language plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment