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

conversion from zero int to time is not compatible with MySQL #25285

Closed
tangenta opened this issue Jun 9, 2021 · 2 comments · Fixed by #25728
Closed

conversion from zero int to time is not compatible with MySQL #25285

tangenta opened this issue Jun 9, 2021 · 2 comments · Fixed by #25728
Assignees
Labels
severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. type/compatibility

Comments

@tangenta
Copy link
Contributor

tangenta commented Jun 9, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> select @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Make sure sql_mode contains "NO_ZERO_DATE".

drop table if exists t;
create table t (a int);
insert into t values (0);
alter table t modify column a date;

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

mysql> alter table t modify column a date;
ERROR 1292 (22007): Incorrect date value: '0' for column 'a' at row 1

3. What did you see instead (Required)

mysql> alter table t modify column a date;
Query OK, 0 rows affected (0.58 sec)

mysql> select * from t;
+------------+
| a          |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.01 sec)

4. What is your TiDB version? (Required)

master

commit f81ef5579551a0523d18b049eb25ab3375bcfb48 (HEAD, upstream/master)
Author: Yuanjia Zhang <zhangyuanjia@pingcap.com>
Date:   Tue Jun 8 20:08:28 2021 +0800

    planner: solve an incompatible issue about dynamic-mode and TiFlash and enable dynamic mode by default  (#25255)
@tangenta tangenta added the type/bug The issue is confirmed as a bug. label Jun 9, 2021
@tangenta tangenta changed the title changing column type does not aware of NO_ZERO_DATE conversion from zero int to time is not compatible with MySQL Jun 24, 2021
@tangenta
Copy link
Contributor Author

Here are MySQL 8.0 behaviors of casting from zero integer to time-related type:

  • cast in DQL(select date(0))
  • cast in DDL(alter table t modify column a date)
set sql_mode='';
select date(0);
select time(0);
select timestamp(0);
sql_mode date datetime timestamp
‘’(empty) 0000-00-00 00:00:00 0000-00-00 00:00:00
strict_trans_tables 0000-00-00 00:00:00 0000-00-00 00:00:00
allow_invalid_dates 0000-00-00 00:00:00 0000-00-00 00:00:00
no_zero_in_date 0000-00-00 00:00:00 0000-00-00 00:00:00
no_zero_date NULL 00:00:00 NULL
drop table if exists t;
create table t (a int);
insert into t values (0);
alter table t modify column a date;
alter table t modify column a datetime;
alter table t modify column a timestamp;
sql_mode date datetime timestamp
‘’(empty) warning(Out of range value) warning(Out of range value) warning(Out of range value)
strict_trans_tables error(Incorrect date value) error(Incorrect date value) error(Incorrect date value)
allow_invalid_dates warning(Out of range value) warning(Out of range value) warning(Out of range value)
no_zero_in_date warning(Out of range value) warning(Out of range value) warning(Out of range value)
no_zero_date warning(Out of range value) warning(Out of range value) warning(Out of range value)

@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

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

Successfully merging a pull request may close this issue.

2 participants