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

UNION and COALESCE produce different field types for DECIMAL+INT

    XMLWordPrintable

Details

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

    Description

      CREATE OR REPLACE TABLE t1 AS SELECT COALESCE(10.1,CAST(10 AS UNSIGNED)) AS a;
      SHOW CREATE TABLE t1;

      returns

      +-------+------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                         |
      +-------+------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `a` decimal(3,1) NOT NULL DEFAULT '0.0'
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+------------------------------------------------------------------------------------------------------+

      Now if I join the same arguments in UNION:

      CREATE OR REPLACE TABLE t1 AS SELECT 10.1 AS a UNION SELECT CAST(10 AS UNSIGNED);
      SHOW CREATE TABLE t1;

      it returns:

      +-------+-------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                          |
      +-------+-------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `a` decimal(18,1) NOT NULL DEFAULT '0.0'
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+-------------------------------------------------------------------------------------------------------+

      DECIMAL(18,1) for these arguments looks too huge.
      UNION should create DECIMAL(3,1), like COALESCE does.

      Attachments

        Issue Links

          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.