pingcap/tidb

inconsistent result of greatest("2017-02-30", cast("2017-02-02" as date))

Open

#6,740 opened on Jun 4, 2018

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Go (6,186 forks)batch import
compatibility-mysql80component/expressionhelp wantedtype/compatibility

Repository metrics

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

Description

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?

  2. What did you expect to see?

mysql(127.0.0.1)> select greatest(cast("2017-02-02" as date),"2017-02-30");
Field   1:  `greatest(cast("2017-02-02" as date),"2017-02-30")`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8_general_ci (33)
Length:     30
Max_length: 10
Decimals:   31
Flags:


+---------------------------------------------------+
| greatest(cast("2017-02-02" as date),"2017-02-30") |
+---------------------------------------------------+
| 2017-02-30                                        |                                    <====
+---------------------------------------------------+

mysql(127.0.0.1)> select greatest(cast("2017-02-02" as date),cast("2017-02-03" as date));
Field   1:  `greatest(cast("2017-02-02" as date),cast("2017-02-03" as date))`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       DATE   <====
Collation:  utf8_general_ci (33)
Length:     9
Max_length: 10
Decimals:   0
Flags:


+-----------------------------------------------------------------+
| greatest(cast("2017-02-02" as date),cast("2017-02-03" as date)) |
+-----------------------------------------------------------------+
| 2017-02-03                                                      |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
  1. What did you see instead?
tidb(127.0.0.1)> select greatest(cast("2017-02-02" as date),"2017-02-30");
Field   1:  `greatest(cast("2017-02-02" as date),"2017-02-30")`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8_general_ci (33)
Length:     0
Max_length: 19
Decimals:   31
Flags:


+---------------------------------------------------+
| greatest(cast("2017-02-02" as date),"2017-02-30") |
+---------------------------------------------------+
| 2017-02-02 00:00:00                               |                                <====
+---------------------------------------------------+
1 row in set, 1 warning (0.00 sec)


tidb(127.0.0.1)> select greatest(cast("2017-02-02" as date),cast("2017-02-03" as date));
Field   1:  `greatest(cast("2017-02-02" as date),cast("2017-02-03" as date))`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING        <====
Collation:  utf8_general_ci (33)
Length:     0
Max_length: 19
Decimals:   31
Flags:


+-----------------------------------------------------------------+
| greatest(cast("2017-02-02" as date),cast("2017-02-03" as date)) |
+-----------------------------------------------------------------+
| 2017-02-03 00:00:00                                             |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
Release Version: v2.0.0-rc.4-273-gf6a3c3f
Git Commit Hash: f6a3c3f0a55abf454d352ffa2089d7983fc18307
Git Branch: master
UTC Build Time: 2018-06-04 03:37:54
GoVersion: go version go1.10.1 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.0.0-rc.4.1

Contributor guide