pingcap/tidb

zeroDate behavior for date_add and timestampdiff is not consistent in tidb

Open

#15,234 建立於 2020年3月9日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)Go (40,090 star) (6,186 fork)batch import
component/expressionhelp wantedseverity/moderatesig/executiontype/bug

描述

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
mysql> select timestampdiff(day,'0000-00-00 00:00:00','2020-01-01 00:00:00');
+----------------------------------------------------------------+
| timestampdiff(day,'0000-00-00 00:00:00','2020-01-01 00:00:00') |
+----------------------------------------------------------------+
|                                                           NULL |
+----------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select date_add('0000-00-00 00:00:00', interval 2020 year);
+-----------------------------------------------------+
| date_add('0000-00-00 00:00:00', interval 2020 year) |
+-----------------------------------------------------+
| 2019-11-30 00:00:00                                 |
+-----------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
  1. What did you expect to see? timestampdiff and date_add should both return NULL or meaningful result. BTW in mysql both timestampdiff and date_add return NULL

  2. What did you see instead?

mysql> select timestampdiff(day,'0000-00-00 00:00:00','2020-01-01 00:00:00');
+----------------------------------------------------------------+
| timestampdiff(day,'0000-00-00 00:00:00','2020-01-01 00:00:00') |
+----------------------------------------------------------------+
|                                                           NULL |
+----------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select date_add('0000-00-00 00:00:00', interval 2020 year);
+-----------------------------------------------------+
| date_add('0000-00-00 00:00:00', interval 2020 year) |
+-----------------------------------------------------+
| 2019-11-30 00:00:00                                 |
+-----------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

tidb master

貢獻者指南