Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-12504

Wrong data type for LEAST(date_expr,time_expr)

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.2(EOL), 10.3(EOL)
    • 10.3.1
    • OTHER
    • None

    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.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.