Bug #6959 Traditional: ALTER TABLE should fail if invalid values result
Submitted: 2 Dec 2004 18:41 Modified: 21 Aug 2005 10:12
Reporter: Trudy Pelzer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.3-alpha-debug OS:Linux (SuSE 9.1)
Assigned to: Sergei Golubchik CPU Architecture:Any

[2 Dec 2004 18:41] Trudy Pelzer
Description:
Under sql_mode='traditional', all invalid values must be rejected. 
The corollary to this is that, if a change would result in existing 
values becoming invalid, the change must fail. But ALTER TABLE 
currently accepts a data type modification, silently changing 
any resulting invalid values. 

How to repeat:
mysql> set sql_mode='traditional'; 
mysql> create table t1 (col1 int); 
mysql> insert into t1 values(null),(50000); 
 
mysql> select * from t1; 
+-------+ 
| col1  | 
+-------+ 
|  NULL | 
| 50000 | 
+-------+ 
-- This is correct; both values are valid for the table definition. 
 
mysql> alter table t1 modify col1 smallint not null; 
Query OK, 2 rows affected, 2 warnings (0.01 sec) 
Records: 2  Duplicates: 0  Warnings: 2 
-- This is the incorrect response. The values already in the 
table are not valid for the new definition, so ALTER TABLE 
should fail with SQLSTATE 42000 invalid definition for existing values 
 
mysql> show warnings; 
+---------+------+--------------------------------------------------------+ 
| Level   | Code | Message                                                | 
+---------+------+--------------------------------------------------------+ 
| Warning | 1265 | Data truncated for column 'col1' at row 1              | 
| Warning | 1264 | Out of range value adjusted for column 'col1' at row 2 | 
+---------+------+--------------------------------------------------------+ 
-- Each warning shows a result that isn't allowed 
in 'traditional' mode. 
 
mysql> select * from t1; 
+-------+ 
| col1  | 
+-------+ 
|     0 | 
| 32767 | 
+-------+ 
-- Values should still be {NULL,50000}, because ALTER 
TABLE should have failed. 
 

Suggested fix:
[21 Aug 2005 10:12] Sergei Golubchik
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 
http://www.mysql.com/downloads/