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

Using NO_ZERO_IN_DATE without strict mode has some incompatible behaviors with MySQL #59790

Open
Tracked by #59410
YangKeao opened this issue Feb 26, 2025 · 0 comments
Open
Tracked by #59410
Labels
component/expression severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@YangKeao
Copy link
Member

Bug Report

Using NO_ZERO_IN_DATE without strict mode is deprecated, so this issue is only here to record and it's marked as minor.

1. Minimal reproduce step (Required)

SET SQL_MODE='NO_ZERO_DATE'; CREATE TABLE t1 (id INT PRIMARY KEY, d DATE); CREATE VIEW v1 AS SELECT * FROM t1 WHERE d = '0000-00-00'; INSERT INTO t1 VALUES (1, '0000-00-00'); SELECT * FROM v1 ORDER BY id; DROP VIEW v1; DROP TABLE t1; SET SQL_MODE=default;
SET SQL_MODE='NO_ZERO_IN_DATE'; CREATE TABLE t1 (d DATE DEFAULT '2023-00-01'); INSERT INTO t1 VALUES (); SELECT * FROM t1 ORDER BY d; DROP TABLE t1; SET SQL_MODE=default;

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

mysql> SET SQL_MODE='NO_ZERO_DATE'; CREATE TABLE t1 (id INT PRIMARY KEY, d DATE); CREATE VIEW v1 AS SELECT * FROM t1 WHERE d = '0000-00-00'; INSERT INTO t1 VALUES (1, '0000-00-00'); SELECT * FROM v1 ORDER BY id; DROP VIEW v1; DROP TABLE t1; SET SQL_MODE=default;
Query OK, 0 rows affected, 1 warning (0.01 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected, 1 warning (0.01 sec)

ERROR 1525 (HY000): Incorrect DATE value: '0000-00-00'
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> SET SQL_MODE='NO_ZERO_IN_DATE'; CREATE TABLE t1 (d DATE DEFAULT '2023-00-01'); INSERT INTO t1 VALUES (); SELECT * FROM t1 ORDER BY d; DROP TABLE t1; SET SQL_MODE=default;
Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.08 sec)

Query OK, 1 row affected (0.00 sec)

+------------+
| d          |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.00 sec)

3. What did you see instead (Required)

mysql> SET SQL_MODE='NO_ZERO_DATE'; CREATE TABLE t1 (id INT PRIMARY KEY, d DATE); CREATE VIEW v1 AS SELECT * FROM t1 WHERE d = '0000-00-00'; INSERT INTO t1 VALUES (1, '0000-00-00'); SELECT * FROM v1 ORDER BY id; DROP VIEW v1; DROP TABLE t1; SET SQL_MODE=default;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.05 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 1 row affected, 1 warning (0.00 sec)

Empty set, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.10 sec)

Query OK, 0 rows affected (0.08 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> SET SQL_MODE='NO_ZERO_IN_DATE'; CREATE TABLE t1 (d DATE DEFAULT '2023-00-01'); INSERT INTO t1 VALUES (); SELECT * FROM t1 ORDER BY d; DROP TABLE t1; SET SQL_MODE=default;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 1 row affected (0.02 sec)

+------------+
| d          |
+------------+
| 2023-00-01 |
+------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.08 sec)

Query OK, 0 rows affected (0.00 sec)

4. What is your TiDB version? (Required)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

2 participants