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

TiDB does not handle NO_ZERO_IN_DATE correctly in cast #54269

Open
lcwangchao opened this issue Jun 27, 2024 · 1 comment
Open

TiDB does not handle NO_ZERO_IN_DATE correctly in cast #54269

lcwangchao opened this issue Jun 27, 2024 · 1 comment

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

> set @@sql_mode='NO_ZERO_IN_DATE';
> select cast('2022-01-00' as date);

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

In Mysql8.0:

mysql> set @@sql_mode='NO_ZERO_IN_DATE';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select cast('2022-01-00' as date);
+----------------------------+
| cast('2022-01-00' as date) |
+----------------------------+
| NULL                       |
+----------------------------+
1 row in set, 1 warning (0.00 sec)

3. What did you see instead (Required)

In TiDB:

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

mysql> select cast('2022-01-00' as date);
+----------------------------+
| cast('2022-01-00' as date) |
+----------------------------+
| 2022-01-00                 |
+----------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

@zanmato1984
Copy link
Contributor

NO_ZERO_IN_DATE is deprecated in MySQL 8.0. And the reason is that MySQL thinks it should be used in conjunction with strict mode (hence the deprecation).

Meanwhile in TiDB, if used with strict mode, insertion of date values with 0 month or day behaves the same as MySQL, though simple selection does not:

tidb> set @@sql_mode='NO_ZERO_IN_DATE,STRICT_ALL_TABLES,STRICT_TRANS_TABLES';
Query OK, 0 rows affected (0.00 sec)

tidb> select cast('2022-01-00' as date);
+----------------------------+
| cast('2022-01-00' as date) |
+----------------------------+
| 2022-01-00                 |
+----------------------------+
1 row in set (0.00 sec)

tidb> insert into t values(cast('2022-01-00' as date));
ERROR 1292 (22007): Incorrect date value: '2022-01-00' for column 'i' at row 1

So I'm lowering the severity to moderate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants