I would like to convert a column in mysql from varchar to enum. If my new enum values include the existing values, will I lose existing values in that column?
For copy paste junkies like myself, given the following output from PROCEDURE ANALYSE()
SELECT status FROM post PROCEDURE ANALYSE()\G
*************************** 1. row ***************************
Field_name: crawling.post.status
Min_value: done
Max_value: pulled
Min_length: 3
Max_length: 6
Empties_or_zeros: 0
Nulls: 0
Avg_value_or_avg_length: 3.7880
Std: NULL
Optimal_fieldtype: ENUM('done','new','pulled') NOT NULL
And using the following command to convert my status column to enum:
ALTER TABLE post MODIFY COLUMN status ENUM('done', 'new', 'pulled') DEFAULT 'new';
It's ok to skip the DEFAULT 'new'.
No, if the values are included in the enum you won't lose data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With