[MDEV-12582] Wrong data type for CREATE..SELECT MAX(COALESCE(timestamp_column)) Created: 2017-04-25  Updated: 2017-04-25  Resolved: 2017-04-25

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

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

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed

 Description   

I run this script:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a TIMESTAMP);
DROP TABLE IF EXISTS t2;
CREATE TABLE t2 AS SELECT
  MAX(a),
  COALESCE(a),
  COALESCE(MAX(a)),
  MAX(COALESCE(a))
FROM t1;
SHOW CREATE TABLE t2;

+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `MAX(a)` timestamp NULL DEFAULT NULL,
  `COALESCE(a)` timestamp NULL DEFAULT NULL,
  `COALESCE(MAX(a))` timestamp NULL DEFAULT NULL,
  `MAX(COALESCE(a))` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Notice, it creates TIMESTAMP fields for all expression but MAX(COALESCE(a)). Looks confusing.

Moreover, if I run the client as:

mysql --column-type-info test

and execute this script:

SELECT
  MAX(a),
  COALESCE(a),
  COALESCE(MAX(a)),
  MAX(COALESCE(a))
FROM t1;

Field   1:  `MAX(a)`
Type:       TIMESTAMP
...
Field   2:  `COALESCE(a)`
Type:       TIMESTAMP
...
Field   3:  `COALESCE(MAX(a))`
Type:       TIMESTAMP
...
Field   4:  `MAX(COALESCE(a))`
Type:       TIMESTAMP
Collation:  binary (63)

It correctly reports TIMESTAP for all columns.



 Comments   
Comment by Alexander Barkov [ 2017-04-25 ]

Pushed into bb-10.2-ext

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