Created
September 15, 2021 12:20
-
-
Save claudiobusatto/21e3dad8fef6f40cf2a9fd8287199816 to your computer and use it in GitHub Desktop.
Template of an update using a for loop in plpgsql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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