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

CHAR creates different data types in hybrid functions vs UNION

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
    • Fix Version/s: 10.4
    • Component/s: Data types
    • Labels:
      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

            • Assignee:
              bar Alexander Barkov
              Reporter:
              bar Alexander Barkov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: