Bug #105379 select greatest("2020-12-12 12:12:12a", cast("2020-12-12 12:12:12" as datetime))
Submitted: 29 Oct 2021 9:28 Modified: 29 Oct 2021 9:36
Reporter: Huaiyu Xu Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:8.0, 5.7 OS:MacOS
Assigned to: CPU Architecture:x86

[29 Oct 2021 9:28] Huaiyu Xu
Description:
unexpected result of `select greatest("2020-12-12 12:12:12a", cast("2020-12-12 12:12:12" as datetime))` 

How to repeat:
mysql> select greatest("2020-12-12 12:12:12a", cast("2020-12-12 12:12:12" as datetime));

+---------------------------------------------------------------------------+
| greatest("2020-12-12 12:12:12a", cast("2020-12-12 12:12:12" as datetime)) |
+---------------------------------------------------------------------------+
| 2020-12-12 12:12:12                                                       |
+---------------------------------------------------------------------------+
1 row in set, 1 warning (0.01 sec)

mysql> select greatest("12:12:12a", cast("12:12:12" as time));

+-------------------------------------------------+
| greatest("12:12:12a", cast("12:12:12" as time)) |
+-------------------------------------------------+
| 12:12:12a                                       |
+-------------------------------------------------+
1 row in set (0.00 sec)

Suggested fix:
`select greatest("2020-12-12 12:12:12a", cast("2020-12-12 12:12:12" as datetime));` should return `"2020-12-12 12:12:12a"`
[29 Oct 2021 9:36] MySQL Verification Team
Hello Huaiyu Xu,

Thank you for the report and test case.

regards,
Umesh