[MDEV-5699] CAST(TIME'10:10:10' AS DATE) - regression Created: 2014-02-18  Updated: 2022-11-01  Resolved: 2022-11-01

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 10.0.8
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

CAST(TIME'10:10:10' AS DATE) returns '2010-10-10' in MariaDB-5.5 and
in MySQL.

MariaDB-10.0 returns '0000-00-00'.



 Comments   
Comment by Sergei Golubchik [ 2014-02-20 ]

Is that bad? I think the new result is ok. The date part of TIME'10:10:10' is DATE'0000-00-00'. You can see that explicitly when casting to datetime, it'll be DATETIME'0000-00-00 10:10:10'.

There's no logical explanation why the date part of TIME'10:10:10' shoud be '2010-10-10'. And I don't consider "because we internally cast time to a string and then to date" a particularly convincing explanation.

Compare, for example, with double→integer cast:

MariaDB [test]> select concat(1e15), cast(1e15 as unsigned);
+--------------+------------------------+
| concat(1e15) | cast(1e15 as unsigned) |
+--------------+------------------------+
| 1e15         |       1000000000000000 |
+--------------+------------------------+

when casted to a string, it's "1e15". If you cast this string to an integer, you get "1". But double→integer cast is not using strings, that's you get the correct result — the integer part of the floating-point number.

Comment by Sergei Golubchik [ 2022-11-01 ]

time->datetime is now works according to the standard, it uses CURRENT_DATE. So,
CAST(TIME'10:10:10' AS DATE) is CURRENT_DATE now.

Generated at Thu Feb 08 07:06:22 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.