Skip to content

Instantly share code, notes, and snippets.

@hasanisaeed
Created September 22, 2021 07:33
Show Gist options
  • Save hasanisaeed/babe1892abefedcc9078b4e99aa8a9a8 to your computer and use it in GitHub Desktop.
Save hasanisaeed/babe1892abefedcc9078b4e99aa8a9a8 to your computer and use it in GitHub Desktop.
Postgresql: Change field name in all table.
do
$$
declare
l_rec record;
begin
for l_rec in (select table_schema, table_name, column_name
from information_schema.columns
where table_schema = 'public'
and column_name = 'mount') loop
execute format ('alter table %I.%I rename column mount to amount', l_rec.table_schema, l_rec.table_name);
end loop;
end;
$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment