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

Different field types for equivalent NULLIF and IF vs CASE with AVG(int_field) and 0e0 arguments

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.0, 10.1
    • 10.0.23
    • OTHER
    • None

    Description

      This script:

      DROP TABLE IF EXISTS t1,t2;
      CREATE TABLE t1 (c1 INT DEFAULT NULL);
      INSERT INTO t1 (c1) VALUES (1),(2),(3),(4);
      CREATE TABLE t2
      SELECT
        NULLIF(AVG(c1),0e0) AS c1,
        IF(AVG(c1)=0e0,NULL,AVG(c1)) AS c2,
        CASE WHEN AVG(c1)=0e0 THEN 0e0 ELSE AVG(c1) END AS c3
      FROM t1;
      SHOW CREATE TABLE t2;

      returns

      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                |
      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | t2    | CREATE TABLE `t2` (
        `c1` decimal(14,4) DEFAULT NULL,
        `c2` decimal(14,4) DEFAULT NULL,
        `c3` double DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+

      All three columns should be of the same data type.

      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.