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

Although the CASE WHEN clause returns the same value as the direct concatenation, NULLIF yields different results in each case.

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.4.2
    • 10.5
    • Data types
    • None
    • ubuntu 20.04

    Description

      select nullif(SPACE(5), case when false then ('TEST') else ('l' || 'o') end) as c1;
      +-------+
      | c1    |
      +-------+
      |       |
      +-------+
      1 row in set, 2 warnings (0.00 sec)
       
       
       
      select nullif(SPACE(5), ('l' || 'o')) as c1;
      +------+
      | c1   |
      +------+
      | NULL |
      +------+
      1 row in set, 3 warnings (0.00 sec)
       
      
      

      The condition for CASE WHEN is FALSE, so this clause should return the result of (l || o). This statement should return the same value as SELECT NULLIF(SPACE(5), ('l' || 'o')) AS c1;, but the actual result is not the same.

      Attachments

        Activity

          danblack Daniel Black added a comment -

          ifnull appears to be taking the common type of its arguments, and then casting the expressions to that.

          To the first, Like MDEV-35121 - 'i' || 'o' is 0. As its in a case statement with a string its actually "0". By space(5) as a string is not-null so 5 spaces is the answer.

          The second case its a 0 as a number. From warnings it evaluated the spaces to not-null and the tried to convert to decimal for output. Interesting on 10.5 I got 5 warnings.

          11.5 warnings from select nullif(SPACE(5), ('l'

          +---------+------+--------------------------------------------+
          | Level   | Code | Message                                    |
          +---------+------+--------------------------------------------+
          | Warning | 1292 | Truncated incorrect DECIMAL value: '     ' |
          | Warning | 1292 | Truncated incorrect DOUBLE value: 'l'      |
          | Warning | 1292 | Truncated incorrect DOUBLE value: 'o'      |
          +---------+------+--------------------------------------------+
          

          This is the same result as below. "dog" is not null, but as a decimal its NULL.

          10.5.27-5673cbe0941e105eb73b5ecf651a529f8e717b52

          MariaDB [(none)]> select nullif("dog", 0) as c;
          Field   1:  `c`
          Org_field:  ``
          Catalog:    `def`
          Database:   ``
          Table:      ``
          Org_table:  ``
          Type:       VAR_STRING
          Collation:  utf8_general_ci (33)
          Length:     9
          Max_length: 0
          Decimals:   39
          Flags:      
           
           
          +------+
          | c    |
          +------+
          | NULL |
          +------+
          1 row in set, 1 warning (0.001 sec)
           
          MariaDB [(none)]> show warnings;
          +---------+------+------------------------------------------+
          | Level   | Code | Message                                  |
          +---------+------+------------------------------------------+
          | Warning | 1292 | Truncated incorrect DECIMAL value: 'dog' |
          +---------+------+------------------------------------------+
          1 row in set (0.001 sec)
          

          danblack Daniel Black added a comment - ifnull appears to be taking the common type of its arguments, and then casting the expressions to that. To the first, Like MDEV-35121 - 'i' || 'o' is 0. As its in a case statement with a string its actually "0". By space(5) as a string is not-null so 5 spaces is the answer. The second case its a 0 as a number. From warnings it evaluated the spaces to not-null and the tried to convert to decimal for output. Interesting on 10.5 I got 5 warnings. 11.5 warnings from select nullif(SPACE(5), ('l' +---------+------+--------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------+ | Warning | 1292 | Truncated incorrect DECIMAL value: ' ' | | Warning | 1292 | Truncated incorrect DOUBLE value: 'l' | | Warning | 1292 | Truncated incorrect DOUBLE value: 'o' | +---------+------+--------------------------------------------+ This is the same result as below. "dog" is not null, but as a decimal its NULL. 10.5.27-5673cbe0941e105eb73b5ecf651a529f8e717b52 MariaDB [(none)]> select nullif("dog", 0) as c; Field 1: `c` Org_field: `` Catalog: `def` Database: `` Table: `` Org_table: `` Type: VAR_STRING Collation: utf8_general_ci (33) Length: 9 Max_length: 0 Decimals: 39 Flags:     +------+ | c | +------+ | NULL | +------+ 1 row in set, 1 warning (0.001 sec)   MariaDB [(none)]> show warnings; +---------+------+------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------+ | Warning | 1292 | Truncated incorrect DECIMAL value: 'dog' | +---------+------+------------------------------------------+ 1 row in set (0.001 sec)

          People

            bar Alexander Barkov
            Wangdada HeShan
            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.