I need to alter the Data Type of a named column (let's call them 'photo') across all the tables in a schema.
For example: I have 300 tables with identical structure (except the data in each row of course). But I have to change the varchar(255) in the photo column to (500) on every table. Is there a way to do it without going through every table and doing it manually?
I tried everything I found on the internet. Used ChatGPT (useless as always) but to no avail.
An example, obviously not tested on your instance, so try out on test database first. In
psqldo:UPDATE
Per Laurenz Albe's suggestion changed
relnametooidin the sub-query and thenpg.relnametopg.oid::regclassin the outer query as extra precaution against SQL injection.Change the
relnamespacevalue to the schema you are looking to change the tables in.