[MDEV-12504] Wrong data type for LEAST(date_expr,time_expr) Created: 2017-04-14  Updated: 2017-04-22  Resolved: 2017-04-22

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 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: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
Relates
relates to MDEV-12506 Split Item_func_min_max::fix_length_a... Closed

 Description   

This query:

SELECT
  LEAST(DATE'2001-01-01', TIME'10:20:30') AS c1,
  CONCAT(LEAST(DATE'2001-01-01', TIME'10:20:30')) AS c2;

returns a good result:

+---------------------+---------------------+
| c1                  | c2                  |
+---------------------+---------------------+
| 2001-01-01 00:00:00 | 2001-01-01 00:00:00 |
+---------------------+---------------------+

Now I try the same query in CREATE..SELECT

DROP TABLE IF EXISTS t1;
SET sql_mode='';
CREATE TABLE t1 AS SELECT
  LEAST(DATE'2001-01-01', TIME'10:20:30') AS c1,
  CONCAT(LEAST(DATE'2001-01-01', TIME'10:20:30')) AS c2;
SHOW WARNINGS;
SELECT * FROM t1;

It returns a warning:

+---------+------+-----------------------------------------+
| Level   | Code | Message                                 |
+---------+------+-----------------------------------------+
| Warning | 1265 | Data truncated for column 'c2' at row 1 |
+---------+------+-----------------------------------------+

And this result set:

+---------------------+------------+
| c1                  | c2         |
+---------------------+------------+
| 2001-01-01 00:00:00 | 2001-01-01 |
+---------------------+------------+

Notice, the c2 value was truncated.

Now I do:

SHOW CREATE TABLE t1;

+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                        |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `c1` datetime NOT NULL,
  `c2` varchar(10) CHARACTER SET utf8 NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+

Notice, the data type for the column c2 is too short.


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