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

Function SUBTIME should return NULL with a warning if its argument is an invalid time value. #11175

Closed
SunRunAway opened this issue Jul 10, 2019 · 2 comments · Fixed by #11262
Labels
component/expression help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/compatibility type/enhancement The issue or PR belongs to an enhancement.

Comments

@SunRunAway
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
SELECT SUBTIME(-32073, 0);
SELECT SUBTIME(0, -32073);
  1. What did you expect to see?

In MySQL 5.7 and MySQL 8.0,

mysql> SELECT SUBTIME(-32073, 0); show warnings;
+--------------------+
| SUBTIME(-32073, 0) |
+--------------------+
| NULL               |
+--------------------+
1 row in set, 1 warning (0.00 sec)

+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect time value: '-32073' |
+---------+------+------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT SUBTIME(0, -32073); show warnings;
+--------------------+
| SUBTIME(0, -32073) |
+--------------------+
| NULL               |
+--------------------+
1 row in set, 1 warning (0.00 sec)

+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect time value: '-32073' |
+---------+------+------------------------------------------+
1 row in set (0.00 sec)
  1. What did you see instead?

In TiDB,

mysql> SELECT SUBTIME(-32073, 0);
ERROR 1292 (22007): Truncated incorrect time value: '-32073'
mysql> SELECT SUBTIME(0, -32073);
ERROR 1292 (22007): Truncated incorrect time value: '-32073'
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    fdbc149
@SunRunAway SunRunAway added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. and removed help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Jul 12, 2019
@tcmichael
Copy link

Refered to https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html, many of time functions returns NULL when the arguments are invalid, except SUBTIME. Shall we decide which arguments are invalid, will SUBTIME returns NULL

@SunRunAway
Copy link
Contributor Author

Hi, @tcmichael
TiDB aims to be compatible with MySQL 5.7, so SUBTIME is best to behave like it even if it is undocumented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/compatibility type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
2 participants