tidb
tidb copied to clipboard
Insert into int field with '' failed
Please answer these questions before submitting your issue. Thanks!
- What did you do? If possible, provide a recipe for reproducing the error.
CREATE TABLE test(
i1 INT(11),
s1 VARCHAR(16)
)
INSERT INTO test(i1,s1) VALUES ('11','aa'); //ok
INSERT INTO test(i1,s1) VALUES ('','aa'); //Error 'Data Truncated'
INSERT INTO test(i1,s1) VALUES (NULL,'aa') //ok
- What did you expect to see?
While in mysql 5.7,the following sql returns ok
INSERT INTO test(i1,s1) VALUES ('','aa');
- What did you see instead?
//Error 'Data Truncated'
- What version of TiDB are you using (
tidb-server -Vor runselect tidb_version();on TiDB)?
Release Version: v1.0.6-1-g17c1319 Git Commit Hash: 17c13192136c1f0bf26db6dec994b9f1b43c90f0 Git Branch: release-1.0 UTC Build Time: 2018-01-09 09:07:08
It comes to me that mysql raises an error:
mysql> CREATE TABLE test(
-> i1 INT(11),
-> s1 VARCHAR(16)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO test(i1,s1) VALUES ('','aa');
ERROR 1366 (HY000): Incorrect integer value: '' for column 'i1' at row 1
My mysql version is 5.7.21
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.7.21, for osx10.13 (x86_64) using EditLine wrapper
Connection id: 5
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server version: 5.7.21-debug Homebrew
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 2 min 32 sec
Threads: 1 Questions: 17 Slow queries: 0 Opens: 107 Flush tables: 1 Open tables: 100 Queries per second avg: 0.111
--------------
@PureWhiteWu In the case you present, TiDB behaves the same as MySQL, this error is caused by the strict sql mode, for a work around, you can:
set @@sql_mode='';
INSERT INTO test(i1,s1) VALUES ('','aa');