Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 5.5.40, 10.0.14
    • 10.1.2
    • Temporal Types
    • None

    Description

      The manual at https://mariadb.com/kb/en/mariadb/documentation/functions-and-operators/control-flow-functions/nullif/ says that NULLIF(expr1,expr2) is the same as CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END.
      In fact it is not always true.

      DROP TABLE IF EXISTS t1,t2;
      CREATE TABLE t1 (a TIME);
      CREATE TABLE t2 AS SELECT a,NULLIF(a,a), CASE WHEN a=a THEN NULL ELSE a END FROM t1;
      SHOW CREATE TABLE t2;

      returns:

      +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                                           |
      +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | t2    | CREATE TABLE `t2` (
        `a` time DEFAULT NULL,
        `NULLIF(a,a)` varchar(10) DEFAULT NULL,
        `CASE WHEN a=a THEN NULL ELSE a END` time DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

      Notice, NULLIF erroneously created a VARCHAR column, while CASE correctly created a TIME column.

      Attachments

        Activity

          bar Alexander Barkov created issue -
          bar Alexander Barkov made changes -
          Field Original Value New Value
          Description The manual at https://mariadb.com/kb/en/mariadb/documentation/functions-and-operators/control-flow-functions/nullif/ says that NULLIF(expr1,expr2)
          is the same as CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END.
          In fact it is not always true.
          {code:sql}
          DROP TABLE IF EXISTS t1,t2;
          CREATE TABLE t1 (a TIME);
          CREATE TABLE t2 AS SELECT a,NULLIF(a,a), CASE WHEN a=a THEN NULL ELSE a END FROM t1;
          SHOW CREATE TABLE t2;
          {code}
          returns:
          {noformat}
          +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          | Table | Create Table |
          +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          | t2 | CREATE TABLE `t2` (
            `a` time DEFAULT NULL,
            `NULLIF(a,a)` varchar(10) DEFAULT NULL,
            `CASE WHEN a=a THEN NULL ELSE a END` time DEFAULT NULL
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
          +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          {noformat}
          Notice, NULLIF erroneously created a VARCHAR column, while CASE correctly created a TIME column.
          The manual at https://mariadb.com/kb/en/mariadb/documentation/functions-and-operators/control-flow-functions/nullif/ says that {{NULLIF(expr1,expr2)}} is the same as {{CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END}}.
          In fact it is not always true.
          {code:sql}
          DROP TABLE IF EXISTS t1,t2;
          CREATE TABLE t1 (a TIME);
          CREATE TABLE t2 AS SELECT a,NULLIF(a,a), CASE WHEN a=a THEN NULL ELSE a END FROM t1;
          SHOW CREATE TABLE t2;
          {code}
          returns:
          {noformat}
          +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          | Table | Create Table |
          +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          | t2 | CREATE TABLE `t2` (
            `a` time DEFAULT NULL,
            `NULLIF(a,a)` varchar(10) DEFAULT NULL,
            `CASE WHEN a=a THEN NULL ELSE a END` time DEFAULT NULL
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
          +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          {noformat}
          Notice, NULLIF erroneously created a VARCHAR column, while CASE correctly created a TIME column.
          serg Sergei Golubchik made changes -
          Fix Version/s 10.0 [ 16000 ]
          bar Alexander Barkov made changes -
          Component/s OTHER [ 10125 ]
          Fix Version/s 10.1.2 [ 15801 ]
          Fix Version/s 10.0 [ 16000 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Component/s Temporal Types [ 11000 ]
          Component/s OTHER [ 10125 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Workflow MariaDB v2 [ 58108 ] MariaDB v3 [ 65530 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 65530 ] MariaDB v4 [ 148395 ]

          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.