Answer the question
In order to leave comments, you need to log in
Change column datatype in all tables?
There was a task to change the data type of the column created_at
and updated_at
from the type
timestamptz
to normal timestamp
in all tables in the database, they were converted to this type as a result of dumpMysql migration using pgloader to the PostgreSQl database.
I decided to implement this with a sql query, but I have not yet found an answer to my question on the Internet. I would be grateful for your help
My request:
select
distinct
string_agg(concat('ALTER_TABLE ', col.table_name, ' ALTER COLUMN ', col.column_name , ' TYPE timestamp '), ';')
FROM information_schema.columns col
WHERE
col.table_catalog = 'api2' AND
col.table_schema = 'public' AND
col.column_name = 'created_at' or col.column_name = 'updated_at';
select
distinct 'ALTER_TABLE ', col.table_name, ' ALTER COLUMN ', col.column_name , ' TYPE timestamp '
FROM information_schema.columns col
WHERE
col.table_catalog = 'api2' AND
col.table_schema = 'public' AND
col.column_name = 'created_at' or col.column_name = 'updated_at';
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question