pingcap/tidb

zeroDate behavior for date_add and timestampdiff is not consistent in tidb

Open

#15.234 aperta il 9 mar 2020

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)Go (6186 fork)batch import
component/expressionhelp wantedseverity/moderatesig/executiontype/bug

Metriche repository

Star
 (40.090 star)
Metriche merge PR
 (Merge medio 14g 4h) (346 PR mergiate in 30 g)

Descrizione

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

Guida contributor