Change a Column Type in Postgres

Apr 20, 2021 min read

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:

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

Example Use:

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