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

CHAR creates different data types in hybrid functions vs UNION

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
    • 10.4
    • Data types
    • None

    Description

      I run this script:

      DROP TABLE IF EXISTS t1,t2,t3;
      CREATE TABLE t1 (a CHAR(1), b CHAR(2));
      CREATE TABLE t2 AS SELECT COALESCE(a,b) AS c FROM t1;
      CREATE TABLE t3 AS SELECT a FROM t1 UNION SELECT b FROM t1;
      DESC t2;
      DESC t3;
      

      It produces these two result sets:

      +-------+------------+------+-----+---------+-------+
      | Field | Type       | Null | Key | Default | Extra |
      +-------+------------+------+-----+---------+-------+
      | c     | varchar(2) | YES  |     | NULL    |       |
      +-------+------------+------+-----+---------+-------+
      

      +-------+---------+------+-----+---------+-------+
      | Field | Type    | Null | Key | Default | Extra |
      +-------+---------+------+-----+---------+-------+
      | a     | char(2) | YES  |     | NULL    |       |
      +-------+---------+------+-----+---------+-------+
      

      Notice:

      • CHAR + CHAR gives VARCHAR in COALESCE
      • CHAR + CHAR gives CHAR in UNION

      The latter looks more correct.
      Hybrid functions should be fixed to preserve the 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:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.