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

CASE returns unexpected result with a YEAR(2) field

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.2, 10.3, 10.4, 10.5, 10.6
    • 10.1, 10.3
    • None
    • None

    Description

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a YEAR(2));
      INSERT INTO t1 VALUES (0);
      SELECT a,NULLIF(a,2000),CASE a WHEN 2000 THEN NULL ELSE 2000 END FROM t1;

      returns

      +------+----------------+------------------------------------------+
      | a    | NULLIF(a,2000) | CASE a WHEN 2000 THEN NULL ELSE 2000 END |
      +------+----------------+------------------------------------------+
      |   00 |           NULL |                                     2000 |
      +------+----------------+------------------------------------------+

      The result for CASE looks wrong. It should return NULL, similar to what NULLIF does.

      Note, if I slightly rewrite CASE, it works fine:

      mysql> SELECT CASE WHEN a=2000 THEN NULL ELSE 2000 END FROM t1;
      +------------------------------------------+
      | CASE WHEN a=2000 THEN NULL ELSE 2000 END |
      +------------------------------------------+
      |                                     NULL |
      +------------------------------------------+

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:

              Git Integration

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