TIMESTAMPADD
does not return correct data type when parameter is DateTime type #39213
Open
Description
Enhancement
This issue is found during #38003
TIMESTAMPADD
should return different DataTypes according to the DataType of its parameters.
e.g.,
MySQL behavior:
mysql> create view v(result) as select timestampadd(second,1.1,cast('1995-01-05 06:32:20.859724' as datetime)) as result;
Query OK, 0 rows affected (0.01 sec)
mysql> desc v;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| result | datetime(1) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
1 row in set (0.01 sec)
mysql> select * from v;
+-----------------------+
| result |
+-----------------------+
| 1995-01-05 06:32:22.1 |
+-----------------------+
1 row in set (0.00 sec)
TiDB behavior:
mysql> create view v(result) as select timestampadd(second,1.1,cast('1995-01-05 06:32:20.859724' as datetime)) as result;
Query OK, 0 rows affected (0.12 sec)
mysql> desc v;
+--------+-------------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+------+---------+-------+
| result | varchar(19) | NO | | NULL | |
+--------+-------------+------+------+---------+-------+
1 row in set (0.01 sec)
mysql> select * from v;
+---------------------+
| result |
+---------------------+
| 1995-01-05 06:32:22 |
+---------------------+
1 row in set (0.00 sec)
When using TIMESTAMPADD
, TiDB always casts the parameter into String, and always returns a String result. This is not efficient and in-compatible with MySQL behavior.
Metadata
Assignees
Labels
This bug affects 5.0.x versions.This bug affects 5.1.x versions.This bug affects 5.2.x versions.This bug affects 5.3.x versions.This bug affects the 5.4.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.This bug affects the 8.5.x(LTS) versions.This bug maybe affects 4.0.x versions.SIG executionThe issue is confirmed as a bug.