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

MEDIUMINT(N<8) creates a wrong data type on conversion to string

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 5.5, 10.0, 10.1, 10.2, 10.3
    • 10.3.7
    • Data types
    • None

    Description

      The MEDIUMINT type has the following characteristics depending on signess:

      MEDIUMINT SIGNED    -8388608..8388607   (7 digits,  8 characters)
      MEDIUNINT UNSIGNED        0..16777215   (8 digits,  8 characters)
      

      But these characteristics are not taken into account precisely:

      CREATE OR REPLACE TABLE t1 (a MEDIUMINT(2), b MEDIUMINT(2) UNSIGNED);
      CREATE OR REPLACE TABLE t2 AS SELECT CONCAT(a),CONCAT(b) FROM t1;
      DESC t2;
      

      +-----------+------------+------+-----+---------+-------+
      | Field     | Type       | Null | Key | Default | Extra |
      +-----------+------------+------+-----+---------+-------+
      | CONCAT(a) | varchar(9) | YES  |     | NULL    |       |
      | CONCAT(b) | varchar(8) | YES  |     | NULL    |       |
      +-----------+------------+------+-----+---------+-------+
      

      For INT-alike data types, the specified length does not constrain the supported type range. So MEDIUMINT(2) still supports the entire MEDIUMINT range (as mentioned above). But in all cases, the maximum possible length on conversion to string is 8, for both signed and unsigned variants.

      The column corresponding to the MEDIUMINT SIGNED erroneously creates a varchar(9) on conversion to string. The expected result is varchar(8).

      Attachments

        Issue Links

          Activity

            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.