Change a Column Type in Postgres

04-20-2021

When designing a database sometimes we get it wrong, here is the command you can use to change a column type for an existing table:

1
ALTER TABLE <table name> ALTER COLUMN <column name> TYPE <new column type> USING <column name>::<column type>

Example Use:

1
ALTER TABLE files ALTER COLUMN file_id TYPE uuid USING file_id::uuid