Hello all,
I am using PostgreSQL. I would like to change all columns within a single database from character to text. Is there a way to do this? If not, is there a way to get a list of all Tables/Columns that are of character data type?
Thanks!
Tim
I found this on the internet, which provides all of the tables and column names. But then is there a way to now change them all to Text?
select col.table_schema,
col.table_name,
col.ordinal_position as column_id,
col.column_name,
col.data_type,
col.character_maximum_length as maximum_length
from information_schema.columns col
join information_schema.tables tab on tab.table_schema = col.table_schema
and tab.table_name = col.table_name
and tab.table_type = 'BASE TABLE'
where col.data_type in ('character varying', 'character',
'"char"', 'name')
and col.table_schema not in ('information_schema', 'pg_catalog')
order by col.table_schema,
col.table_name,
col.ordinal_position;