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

CASE and CASE-alike hybrid functions do not preserve exact data types

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.1(EOL), 10.2(EOL), 10.3(EOL)
    • 10.3.1
    • OTHER

    Description

      This problem is repeatable with CASE, COALESCE, IF, NULLIF, LEAST, GREATEST.
      This problem is not repeatable with IFNULL, which does preserve exact data types.

      FLOAT is converted to DOUBLE

      CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
      CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
      DESCRIBE t2;
      

      +-------------+--------------+------+-----+---------+-------+
      | Field       | Type         | Null | Key | Default | Extra |
      +-------------+--------------+------+-----+---------+-------+
      | COALESCE(a) | double(10,2) | YES  |     | NULL    |       |
      +-------------+--------------+------+-----+---------+-------+
      

      CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
      CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
      DESCRIBE t2;
      

      +------------+--------------+------+-----+---------+-------+
      | Field      | Type         | Null | Key | Default | Extra |
      +------------+--------------+------+-----+---------+-------+
      | LEAST(a,a) | double(19,2) | YES  |     | NULL    |       |
      +------------+--------------+------+-----+---------+-------+
      

      TINYINT is converted to INT

      CREATE OR REPLACE TABLE t1 (a TINYINT(1));
      CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
      DESCRIBE t2;
      

      +-------------+--------+------+-----+---------+-------+
      | Field       | Type   | Null | Key | Default | Extra |
      +-------------+--------+------+-----+---------+-------+
      | COALESCE(a) | int(4) | YES  |     | NULL    |       |
      +-------------+--------+------+-----+---------+-------+
      

      CREATE OR REPLACE TABLE t1 (a TINYINT(1));
      CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
      DESCRIBE t2;
      

      +------------+--------+------+-----+---------+-------+
      | Field      | Type   | Null | Key | Default | Extra |
      +------------+--------+------+-----+---------+-------+
      | LEAST(a,a) | int(4) | YES  |     | NULL    |       |
      +------------+--------+------+-----+---------+-------+
      

      UNION

      Unlike hybrid functions, UNION correctly preserves the exact data types:

      CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
      CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
      DESCRIBE t2;
      

      +-------+-------------+------+-----+---------+-------+
      | Field | Type        | Null | Key | Default | Extra |
      +-------+-------------+------+-----+---------+-------+
      | a     | float(10,2) | YES  |     | NULL    |       |
      +-------+-------------+------+-----+---------+-------+
      

      CREATE OR REPLACE TABLE t1 (a TINYINT(1));
      CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
      DESCRIBE t2;
      

      +-------+------------+------+-----+---------+-------+
      | Field | Type       | Null | Key | Default | Extra |
      +-------+------------+------+-----+---------+-------+
      | a     | tinyint(4) | YES  |     | NULL    |       |
      +-------+------------+------+-----+---------+-------+
      

      Hybrid functions should be fixed to preserve the exact data types, like UNION does.

      Note, UNION is probably wrong with returning tinyint(4) instead of tinyint(1). But this problem will be addressed separately.

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov created issue -
            bar Alexander Barkov made changes -
            Field Original Value New Value
            bar Alexander Barkov made changes -
            Description {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}



            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}
            This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}



            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}
            bar Alexander Barkov made changes -
            Summary CASE and CASE-alike hybrid functions do not preserve exact type types CASE and CASE-alike hybrid functions do not preserve exact data types
            bar Alexander Barkov made changes -
            Description This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}



            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}
            This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            h3. {{FLOAT}} is converted to {{DOUBLE}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}


            h3. {{TINYINT}} is converted to {{INT}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}
            bar Alexander Barkov made changes -
            Description This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            h3. {{FLOAT}} is converted to {{DOUBLE}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}


            h3. {{TINYINT}} is converted to {{INT}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}
            This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}, {{LEAST}}, {{GREATEST}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            h3. {{FLOAT}} is converted to {{DOUBLE}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}


            h3. {{TINYINT}} is converted to {{INT}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}
            bar Alexander Barkov made changes -
            Description This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}, {{LEAST}}, {{GREATEST}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            h3. {{FLOAT}} is converted to {{DOUBLE}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}


            h3. {{TINYINT}} is converted to {{INT}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}
            This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}, {{LEAST}}, {{GREATEST}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            h3. {{FLOAT}} is converted to {{DOUBLE}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            h3. {{TINYINT}} is converted to {{INT}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            h3. {{UNION}}

            Unlike hybrid functions, {{UNION}} correctly preserves the exact data types:

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}

            Hybrid functions should be fixed to preserve the exact data types, like {{UNION}} does.
            bar Alexander Barkov made changes -
            Description This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}, {{LEAST}}, {{GREATEST}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            h3. {{FLOAT}} is converted to {{DOUBLE}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            h3. {{TINYINT}} is converted to {{INT}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            h3. {{UNION}}

            Unlike hybrid functions, {{UNION}} correctly preserves the exact data types:

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}

            Hybrid functions should be fixed to preserve the exact data types, like {{UNION}} does.
            This problem is repeatable with {{CASE}}, {{COALESCE}}, {{IF}}, {{NULLIF}}, {{LEAST}}, {{GREATEST}}.
            This problem is not repeatable with {{IFNULL}}, which does preserve exact data types.

            h3. {{FLOAT}} is converted to {{DOUBLE}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------------+------+-----+---------+-------+
            | COALESCE(a) | double(10,2) | YES | | NULL | |
            +-------------+--------------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------------+------+-----+---------+-------+
            | LEAST(a,a) | double(19,2) | YES | | NULL | |
            +------------+--------------+------+-----+---------+-------+
            {noformat}


            h3. {{TINYINT}} is converted to {{INT}}
            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------------+--------+------+-----+---------+-------+
            | COALESCE(a) | int(4) | YES | | NULL | |
            +-------------+--------+------+-----+---------+-------+
            {noformat}


            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +------------+--------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+--------+------+-----+---------+-------+
            | LEAST(a,a) | int(4) | YES | | NULL | |
            +------------+--------+------+-----+---------+-------+
            {noformat}


            h3. {{UNION}}

            Unlike hybrid functions, {{UNION}} correctly preserves the exact data types:

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a FLOAT(10,2));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+-------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+-------------+------+-----+---------+-------+
            | a | float(10,2) | YES | | NULL | |
            +-------+-------------+------+-----+---------+-------+
            {noformat}

            {code:sql}
            CREATE OR REPLACE TABLE t1 (a TINYINT(1));
            CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1;
            DESCRIBE t2;
            {code}
            {noformat}
            +-------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +-------+------------+------+-----+---------+-------+
            | a | tinyint(4) | YES | | NULL | |
            +-------+------------+------+-----+---------+-------+
            {noformat}

            Hybrid functions should be fixed to preserve the exact data types, like {{UNION}} does.

            Note, {{UNION}} is probably wrong with returning {{tinyint(4)}} instead of {{tinyint(1)}}. But this problem will be addressed separately.

            bar Alexander Barkov made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            bar Alexander Barkov made changes -
            Assignee Alexander Barkov [ bar ] Oleksandr Byelkin [ sanja ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            OK to push

            sanja Oleksandr Byelkin added a comment - OK to push
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Alexander Barkov [ bar ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            bar Alexander Barkov made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]

            Pushed to bb-10.2.ext

            bar Alexander Barkov added a comment - Pushed to bb-10.2.ext
            bar Alexander Barkov made changes -
            Fix Version/s 10.3.1 [ 22532 ]
            Fix Version/s 10.3 [ 22126 ]
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            bar Alexander Barkov made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 80512 ] MariaDB v4 [ 152035 ]

            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.