pingcap/tidb

zeroDate behavior for date_add and timestampdiff is not consistent in tidb

Open

#15.234 geöffnet am 9. März 2020

Auf GitHub ansehen
 (5 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Go (6.186 Forks)batch import
component/expressionhelp wantedseverity/moderatesig/executiontype/bug

Repository-Metriken

Stars
 (40.090 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 14T 4h) (346 gemergte PRs in 30 T)

Beschreibung

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