[MDEV-8875] Wrong metadata for MAX(CAST(time_column AS DATETIME)) Created: 2015-09-30  Updated: 2015-10-08  Resolved: 2015-09-30

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 10.0, 10.1
Fix Version/s: 10.1.8

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: upstream

Sprint: 10.1.8-4

 Description   

I run "mysql --column-type-info test" and execute this SQL script:

SET timestamp=UNIX_TIMESTAMP('2015-01-01 00:00:00');
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a TIME);
INSERT INTO t1 VALUES ('00:00:00'),('00:01:00');
SELECT MAX(CAST(a AS DATETIME)) FROM t1;

It returns the following metadata:

Field   1:  `MAX(CAST(a AS DATETIME))`
...
Type:       VAR_STRING
Collation:  utf8_general_ci (33)
Length:     57
Max_length: 19
Decimals:   0
Flags:  

This is wrong. The expected Type is DATETIME.

Note, if I now run:

DROP TABLE IF EXISTS t2;
CREATE TABLE t2 AS SELECT MAX(CAST(a AS DATETIME)) FROM t1;
SHOW CREATE TABLE t2;

it correctly creates a DATETIME column:

+-------+---------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                  |
+-------+---------------------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `MAX(CAST(a AS DATETIME))` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------+

So the problem is only with the metadata returned.



 Comments   
Comment by Alexander Barkov [ 2015-09-30 ]

Also repeatable in MySQL-5.7.8

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