Chris Chris - 1 year ago 112
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?

Answer Source

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';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download