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

CAST(COALESCE(year_field)) returns wrong value

    XMLWordPrintable

Details

    Description

      This script:

      CREATE OR REPLACE TABLE t1 (a YEAR);
      INSERT INTO t1 VALUES (2000);
      SELECT CAST(a AS DATE), CAST(COALESCE(a) AS DATE) FROM t1;
      SHOW WARNINGS;
      

      produces the following output:

      +-----------------+---------------------------+
      | CAST(a AS DATE) | CAST(COALESCE(a) AS DATE) |
      +-----------------+---------------------------+
      | 2000-00-00      | NULL                      |
      +-----------------+---------------------------+
      1 row in set, 1 warning (0.00 sec)
       
      +---------+------+----------------------------------+
      | Level   | Code | Message                          |
      +---------+------+----------------------------------+
      | Warning | 1292 | Incorrect datetime value: '2000' |
      +---------+------+----------------------------------+
      

      NULL in the second column is wrong. Both columns should return the same value, without warnings.

      This happens because Type_handler_year has a special implementation in Item_get_date():

      bool Type_handler_year::Item_get_date(Item *item, MYSQL_TIME *ltime,
                                                   ulonglong fuzzydate) const
      {
        return item->get_date_from_year(ltime, fuzzydate);
      }
      

      but does not have a similar implementation for Item_func_hybrid_field_type_get_date().

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.