Home > front end >  Migrating existing VARCHAR values to an Enum in Postgres 8
Migrating existing VARCHAR values to an Enum in Postgres 8

Time:09-16

I have a table in production with values in a varchar column, but this column has now to be an enum. I've already created the enum, but how to migrate the existing values to the created Enum.

Will the database automatically map/migrate the existing values to the Enum by simply changing the column type?

Edit:

ALTER TABLE table ALTER COLUMN column TYPE new_enum_created;

I don't know if it might be useful but we use flyway for the migrations.

CodePudding user response:

You have to use a USING clause to tell PostgreSQL how to convert the data:

ALTER TABLE "table" ALTER COLUMN "column"
   TYPE new_enum_created USING "column"::new_enum_created;
  • Related