[MDEV-11874] "Data too long for column" instead of "Invalid default value for" upon ALTER in strict mode Created: 2017-01-23  Updated: 2019-04-29  Resolved: 2019-04-29

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 10.0, 10.1, 10.2
Fix Version/s: 10.4.0

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-7635 update defaults and simplify mysqld c... Closed
relates to MDEV-16421 Make system tables crash safe Closed

 Description   

If we try to create a table with a too long default value for a varchar column, it produces ER_INVALID_DEFAULT "Invalid default value" error regardless the strict mode:

MariaDB [test]> set sql_mode='';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create table t1 (c varchar(1) default 'foo');
ERROR 1067 (42000): Invalid default value for 'c'
MariaDB [test]> 
MariaDB [test]> set sql_mode='STRICT_ALL_TABLES';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create table t1 (c varchar(1) default 'foo');
ERROR 1067 (42000): Invalid default value for 'c'

But if we set the default value via an ALTER statement, the error depends on the strict mode:

MariaDB [test]> create table t1 (c varchar(1));
Query OK, 0 rows affected (0.29 sec)
 
MariaDB [test]> set sql_mode='';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> alter table t1 alter column c set default 'foo';
ERROR 1067 (42000): Invalid default value for 'c'
MariaDB [test]> 
MariaDB [test]> set sql_mode='STRICT_ALL_TABLES';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> alter table t1 alter column c set default 'foo';
ERROR 1406 (22001): Data too long for column 'c' at row 1

It doesn't seem right.

It started happening in 10.0.
5.5 (and MySQL 5.6/5.7) produce the same ER_INVALID_DEFAULT consistently.



 Comments   
Comment by Alexander Barkov [ 2019-04-29 ]

This problem was fixed in 10.4 by the patch for MDEV-16421, which is not safe to backport to 10.2.

Generated at Thu Feb 08 07:53:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.