Chris Chris - 9 months ago 39
SQL Question

Rename all columns from all tables with specific column name in PostgreSQL?

Is there a way I can rename all column names that are called 'location' to 'location_name' within all schemas in my PostgreSQL database?

I am fairly new to SQL and am aware there is an ALTER TABLE command but don't know if it is possible to somehow loop through all tables?


If you have superuser privileges you can make the changes in one sweep in the system catalogs:

UPDATE pg_attribute
SET attname = 'location_name'
WHERE attname = 'location';