pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://tidbcloud.com/free-trial
https://pingcap.com
Apache License 2.0
36.27k stars 5.72k forks source link

When sql_mode is empty, there is a problem creating default values for columns that are out of bounds #52972

Closed zimulala closed 2 weeks ago

zimulala commented 2 weeks ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

set @@sql_mode='';
drop table if exists t1;
create table t1(b tinyint default '11111111');
alter table t1 add column(c tinyint default '11111111');

2. What did you expect to see? (Required)

MySQL 5.7.44 and MySQL 8.0.18

mysql> create table t1(c tinyint default '11111111');
ERROR 1067 (42000): Invalid default value for 'b'

create table t1(b tinyint);
mysql> alter table t1 add column(c tinyint default '11111111');
ERROR 1067 (42000): Invalid default value for 'c'

3. What did you see instead (Required)

tidb> create table t1(b tinyint default '11111111');
Query OK, 0 rows affected, 1 warning (0.01 sec)

tidb> show warnings;
+---------+------+-------------------------------------+
| Level   | Code | Message                             |
+---------+------+-------------------------------------+
| Warning | 1690 | constant 11111111 overflows tinyint |
+---------+------+-------------------------------------+
1 row in set (0.00 sec)

tidb> alter table t1 add column(c tinyint default '11111111');
Query OK, 0 rows affected, 1 warning (0.02 sec)

4. What is your TiDB version? (Required)

master

related https://github.com/pingcap/tidb/issues/51320