All articles
Postgres

Change a Column Type in Postgres

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

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

Tagged

#Postgres

Dealing with something harder than a blog post can fix?

Book a 30-minute call →