v.19.1Improvements
Support for IF NOT EXISTS in ALTER TABLE ADD COLUMN Statements Along with IF EXISTS in Drop/modify/clear/comment COLUMN
Support forIF NOT EXISTSinALTER TABLE ADD COLUMNstatements along withIF EXISTSinDROP/MODIFY/CLEAR/COMMENT COLUMN. #3900 (Boris Granveaud)
Why it matters
This feature helps prevent errors during schema changes by allowing conditional execution ofALTER TABLE operations. It avoids failures when adding a column that already exists or modifying/dropping a column that might not exist, thereby improving the robustness and user experience of schema migrations.How to use it
Users can add the clauseIF NOT EXISTS when adding a new column: ALTER TABLE table_name ADD COLUMN IF NOT EXISTS column_name <datatype>;For dropping, modifying, clearing, or commenting on columns, use
IF EXISTS: ALTER TABLE table_name DROP COLUMN IF EXISTS column_name;
ALTER TABLE table_name MODIFY COLUMN IF EXISTS column_name <datatype>;
ALTER TABLE table_name CLEAR COLUMN IF EXISTS column_name;
ALTER TABLE table_name COMMENT COLUMN IF EXISTS column_name 'comment';