We have a varchar column in a table, that we need to upgrade to enum type.
All the values in the varchar column are valid values in the enumeration. There is no null values in the varchar column.
ALTER TABLE tableName
ALTER COLUMN varcharColumn TYPE enum_type
ERROR: column "varcharColumn" cannot be cast to type enum_type
SQL state: 42804
The round about way is to
- Create another new column with enum type.
- Update the enum type column with the varchar column after typecasting.
- Drop the varchar column.
- Rename the enum type column name to the varchar column name.
Is there a better way to achieve this?
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…