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

Unexpected error on CREATE..SELECT HEX(num)

    XMLWordPrintable

Details

    Description

      SET sql_mode=STRICT_ALL_TABLES;
      DROP TABLE IF EXISTS t1, t2;
      CREATE TABLE t1 (a TINYINT);
      INSERT INTO t1 VALUES (-1);
      CREATE TABLE t2 AS SELECT a, HEX(a) AS h FROM t1;
      

      ERROR 1406 (22001): Data too long for column 'h' at row 1
      

      Looks wrong.

      This script:

      CREATE TABLE t2 AS SELECT a, HEX(a) AS h FROM t1 LIMIT 0;
      SHOW CREATE TABLE t2;
      

      demonstrates that the data type for the column h is too short:

      +-------+--------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                               |
      +-------+--------------------------------------------------------------------------------------------------------------------------------------------+
      | t2    | CREATE TABLE `t2` (
        `a` tinyint(4) DEFAULT NULL,
        `h` varchar(8) CHARACTER SET utf8 DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+--------------------------------------------------------------------------------------------------------------------------------------------+
      

      It should be varchar(16) to fit hex representation of positive completents for negative numbers:

      SELECT a, HEX(a) FROM t1;
      

      +------+------------------+
      | a    | HEX(a)           |
      +------+------------------+
      |   -1 | FFFFFFFFFFFFFFFF |
      +------+------------------+
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              1 Vote for this issue
              Watchers:
              3 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.