Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 10.0.2
-
Fix Version/s: 10.0.12
-
Component/s: None
-
Labels:None
Description
If ALTER TABLE contains multiple parts, and one of them creates a problem for a next one, IF NOT EXISTS or IF EXISTS clause in the following one does not work, the statement still produces an error, and does not add the column at all:
MariaDB [test]> show create table t1; +-------+---------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +-------+---------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) MariaDB [test]> alter table t1 add column a int, add column if not exists a int; ERROR 1060 (42S21): Duplicate column name 'a' MariaDB [test]> show create table t1; +-------+---------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +-------+---------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
Same for DROP COLUMN.
Test case:
create table t1 (i int); alter table t1 add column a int, add column if not exists a int; show create table t1;
revision-id: bar@mariadb.org-20130424142022-u4xhikvoqggze9b0 revno: 3745 branch-nick: 10.0
Gliffy Diagrams
Attachments
Issue Links
- relates to
-
MDEV-318 IF (NOT) EXIST clauses for ALTER TABLE (MWL #252)
-
- Closed
-
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
let's just document that. ALTER isn't executing its clauses sequentially, it's doing everything at once. So all IF [NOT] EXISTS clauses apply to the table structure before ALTER, there's no intermediate state.