Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling STRICT_TRANS_TABLES should allow NULL insert into NOT NULL column with default value #11648

Closed
wjhuang2016 opened this issue Aug 6, 2019 · 5 comments · Fixed by #21237
Labels
affects-4.0 This bug affects 4.0.x versions. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. type/compatibility

Comments

@wjhuang2016
Copy link
Member

Bug Report

  1. What did you do?
create table t1 (id int NOT NULL DEFAULT 8);
SET sql_mode = '';
insert into t1 values (1), (NULL), (2);
  1. What did you expect to see?
mysql> create table t1 (id int NOT NULL DEFAULT 8);
Query OK, 0 rows affected (0.06 sec)

mysql> SET sql_mode = '';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values (1), (NULL), (2);
Query OK, 3 rows affected, 1 warning (0.03 sec)
Records: 3  Duplicates: 0  Warnings: 1

mysql> show warnings;
+---------+------+----------------------------+
| Level   | Code | Message                    |
+---------+------+----------------------------+
| Warning | 1048 | Column 'id' cannot be null |
+---------+------+----------------------------+
1 row in set (0.00 sec)

mysql> select * from t1;
+----+
| id |
+----+
|  1 |
|  0 |
|  2 |
+----+
3 rows in set (0.00 sec)
  1. What did you see instead?
mysql> create table t1 (id int NOT NULL DEFAULT 8);
Query OK, 0 rows affected (0.02 sec)

mysql> SET sql_mode = '';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values (1), (NULL), (2);
ERROR 1048 (23000): Column 'id' cannot be null
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    master
@wjhuang2016 wjhuang2016 added the type/bug The issue is confirmed as a bug. label Aug 6, 2019
@zimulala
Copy link
Contributor

zimulala commented Aug 8, 2019

@wjhuang2016 Thanks for your feedback!
We may not support it in the short term.

@ghost
Copy link

ghost commented Jul 15, 2020

Confirming I can reproduce this against master. The specific issue is that TiDB does not impliment STRICT_TRANS_TABLES as OFF correctly:

drop table if exists t1;
create table t1 (id int NOT NULL DEFAULT 8);
SET sql_mode = 'STRICT_TRANS_TABLES';
insert into t1 values (1), (NULL), (2);
SET sql_mode = '';
insert into t1 values (1), (NULL), (2);

..

mysql> SET sql_mode = 'STRICT_TRANS_TABLES';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values (1), (NULL), (2); -- should fail (correct)
ERROR 1048 (23000): Column 'id' cannot be null
mysql> SET sql_mode = '';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values (1), (NULL), (2); -- should succeed (fails incorrectly)
ERROR 1048 (23000): Column 'id' cannot be null

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-771-gca41972fb
Edition: Community
Git Commit Hash: ca41972fbac068c8a5de107d9075f09ac68842ac
Git Branch: master
UTC Build Time: 2020-07-14 02:41:21
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@ghost ghost changed the title insert into t1 values (1), (NULL), (2); failed in sql_mode '' Disabling STRICT_TRANS_TABLES should allow NULL insert into NOT NULL column with default value Jul 15, 2020
@jebter jebter added the sig/sql-infra SIG: SQL Infra label Nov 16, 2020
@watchpoints
Copy link
Contributor

watchpoints commented Dec 20, 2020

@wjhuang2016 Thanks for your feedback!
We may not support it in the short term.

@zimulala this issue is not picked up?

@wjhuang2016
Copy link
Member Author

@watchpoints I had a PR for it, and I will reopen it soon.

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-4.0 This bug affects 4.0.x versions. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. type/compatibility
Projects
None yet
7 participants