[MDEV-5757] CAST(date_sp_variable AS TIME) returns a wrong result Created: 2014-02-27  Updated: 2018-02-13  Resolved: 2018-02-13

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Temporary
Affects Version/s: 5.5.35, 10.0.8
Fix Version/s: 10.3.5

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

Issue Links:
Duplicate
duplicates MDEV-15293 CAST(AS TIME) returns bad results for... Closed

 Description   

mysql> SELECT CAST(DATE'2001-01-01' AS TIME);
+--------------------------------+
| CAST(DATE'2001-01-01' AS TIME) |
+--------------------------------+
| 00:00:00                       |
+--------------------------------+
1 row in set (0.00 sec)
 
mysql> DROP PROCEDURE IF EXISTS p1;
Query OK, 0 rows affected (0.02 sec)
 
mysql> DELIMITER |;
mysql> create procedure p1()
    -> begin
    ->   declare t date;
    ->   set t=date'2001-01-01';
    ->   select cast(t as time);
    -> end|;
Query OK, 0 rows affected (0.04 sec)
 
mysql> CALL p1|;
+-----------------+
| cast(t as time) |
+-----------------+
| 00:20:01        |
+-----------------+
1 row in set (0.00 sec)
 
Query OK, 0 rows affected, 1 warning (0.00 sec)

The two SELECT queries should return the same result.

The problem happens because Item_splocal::get_date() points
to the generic Item::get_date(), so the conversion happens through a
temporary string value: time -> string -> date.


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