diff options
Diffstat (limited to 'mysql-test/t/auto_increment.test')
-rw-r--r-- | mysql-test/t/auto_increment.test | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index e5986e6755d..8e11a3d68a5 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -168,3 +168,41 @@ update t1 set a=NULL where b=13; update t1 set a=500 where b=14; select * from t1 order by b; drop table t1; + +# +# Test of behavior of ALTER TABLE when coulmn containing NULL or zeroes is +# converted to AUTO_INCREMENT column +# +create table t1 (a bigint); +insert into t1 values (1), (2), (3), (NULL), (NULL); +alter table t1 modify a bigint not null auto_increment primary key; +select * from t1; +drop table t1; + +create table t1 (a bigint); +insert into t1 values (1), (2), (3), (0), (0); +alter table t1 modify a bigint not null auto_increment primary key; +select * from t1; +drop table t1; + +# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode +create table t1 (a bigint); +insert into t1 values (0), (1), (2), (3); +set sql_mode=NO_AUTO_VALUE_ON_ZERO; +alter table t1 modify a bigint not null auto_increment primary key; +set sql_mode= ''; +select * from t1; +drop table t1; + +# It also sensible to preserve zeroes if we are converting auto_increment +# column to auto_increment column (or not touching it at all, which is more +# common case probably) +create table t1 (a int auto_increment primary key , b int null); +set sql_mode=NO_AUTO_VALUE_ON_ZERO; +insert into t1 values (0,1),(1,2),(2,3); +select * from t1; +set sql_mode= ''; +alter table t1 modify b varchar(255); +insert into t1 values (0,4); +select * from t1; +drop table t1; |