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

CAST(MAX(DATE'2001-01-01') AS TIME) returns a wrong result

    XMLWordPrintable

Details

    • 10.2.11

    Description

      CAST from DATE to TIME usually returns zero time 00:00:00:

      SELECT CAST(DATE'2001-01-01' AS TIME)
      

      +--------------------------------+
      | CAST(DATE'2001-01-01' AS TIME) |
      +--------------------------------+
      | 00:00:00                       |
      +--------------------------------+
      

      However, in some cases it works differently:

      SELECT CAST(MAX(DATE'2001-01-01') AS TIME);
      SHOW WARNINGS;
      

      +-------------------------------------+
      | CAST(MAX(DATE'2001-01-01') AS TIME) |
      +-------------------------------------+
      | 00:20:01                            |
      +-------------------------------------+
      1 row in set, 1 warning (0.00 sec)
       
      +---------+------+----------------------------------------------+
      | Level   | Code | Message                                      |
      +---------+------+----------------------------------------------+
      | Warning | 1292 | Truncated incorrect time value: '2001-01-01' |
      +---------+------+----------------------------------------------+
      1 row in set (0.00 sec)
      

      The problem happens because Item_sum_max does not implement its own get_date() method, so execution goes through the generic Item::get_date() which calls val_str() followed by string-to-time conversion.

      Attachments

        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.