[MDEV-5895] Bad results when casting DATE_ADD(..) to some numeric types Created: 2014-03-18  Updated: 2022-09-08

Status: Open
Project: MariaDB Server
Component/s: Data types, Temporal Types
Affects Version/s: 5.5.36, 10.0.9
Fix Version/s: 5.5

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: datatype

Epic Link: Data type cleanups

 Description   

This query

SELECT CAST(DATE_ADD(101, INTERVAL 1 hour_second) AS SIGNED) AS c1, CAST(DATE_ADD(101, INTERVAL 1 hour_second) AS DOUBLE) AS c2,  CAST(DATE_ADD(101, INTERVAL 1 hour_second) AS DECIMAL(20)) AS c3;

returns:

+------+----------------+----------------+
| c1   | c2             | c3             |
+------+----------------+----------------+
| 2000 | 20000101000001 | 20000101000001 |
+------+----------------+----------------+
 

The result must be the same for all three expressions.
The question is: which is correct?

The return value for "DATE_ADD(101, INTERVAL 1 hour_second)"
is '2000-01-01 00:00:01'. But the data type in this context is VARCHAR
(note VARCHAR is correct, as the argument is not a temporal data type!).
So it should probably return 2000 in all three cases, i.e. parse
the returned value as a string, without trying to treat it as a datetime.


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