pingcap/tidb

zeroDate behavior for date_add and timestampdiff is not consistent in tidb

Open

#15,234 opened on Mar 9, 2020

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Go (6,186 forks)batch import
component/expressionhelp wantedseverity/moderatesig/executiontype/bug

Repository metrics

Stars
 (40,090 stars)
PR merge metrics
 (Avg merge 14d 4h) (346 merged PRs in 30d)

Description

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

Contributor guide