Bug #3706 | ALTER TABLE MODIFY COLUMN foo IF NOT EXIST | ||
---|---|---|---|
Submitted: | 11 May 2004 0:58 | Modified: | 21 Feb 2007 13:35 |
Reporter: | Jonathan Lampe | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: DDL | Severity: | S4 (Feature request) |
Version: | OS: | Any | |
Assigned to: | CPU Architecture: | Any |
[11 May 2004 0:58]
Jonathan Lampe
[21 Feb 2007 13:35]
Sveta Smirnova
Thank you for the reasonable feature request.
[16 Dec 2007 7:17]
Adam Dorian
Hi. I was trying to find out a way I can CONDITIONALLY run an alter 'CHANGE COLUMN' statement based upon whether it has already been run before. This is a very important, common practise for large scale applications where scripts need to be re-runabble as part of the deploy process. So I looked up the bug http://bugs.mysql.com/bug.php?id=15037 which states that the IF statement doesnt work as documented (Which it doesnt). Then I came here to find that there is also no 'IF NOT EXIST' syntax for column based. So my question si. In MySQL, how is one supposed to run the following query ONLY if it already hasnt been run before?! Is there any way? ALTER TABLE my_table CHANGE COLUMN old_name new_name VARCHAR(100)
[30 Sep 2008 9:15]
Konstantin Osipov
There is a quite viable workaround now with stored procedure continue handlers. Wrap the statement into a stored procedure and install a condition handler for 'no such column' condition, and you get the desired behavior.
[28 Mar 2012 10:40]
nerijus navickas
This functionality still not available in 5.1 :( It gets quite complicated when you need to maintain existing systems. Believe me I am with big TV company now. For example in production system I have no rights to create SP. As you can't create safe-to-run multiple times script it gets feeling that mySql is not enterprise ready yet. Is it so hard to implement? Found solution (workaround) here (SP based): http://www.cryer.co.uk/brian/mysql/howto_add_column_unless_exists.htm