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

Wrong data type for CREATE..SELECT MAX(COALESCE(timestamp_column))

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL)
    • 10.3.1
    • Temporal Types

    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.

      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.