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

Out-of-range errors when casting hex-hybrid to SIGNED and UNSIGNED

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.2, 10.3
    • Fix Version/s: 10.3.1
    • Component/s: OTHER
    • Labels:

      Description

      These queries work fine:

      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFF AS UNSIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFF AS UNSIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFF AS UNSIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFF AS UNSIGNED);
      

      There queries return an error:

      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFF AS UNSIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFFFF AS UNSIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFFFFFF AS UNSIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED);
      

      ERROR 1264 (22003): Out of range value for column 'CAST(0xFFFFFFFFFF AS UNSIGNED)' at row 1
      

      Adding LIMIT 0 helps to create the table and see what's the problem:

      CREATE OR REPLACE TABLE t1 AS
      SELECT
        CAST(0xFFFFFFFFFF AS UNSIGNED),
        CAST(0xFFFFFFFFFFFF AS UNSIGNED),
        CAST(0xFFFFFFFFFFFFFF AS UNSIGNED),
        CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED) LIMIT 0;
      DESCRIBE t1;
      

      +--------------------------------------+-----------------+------+-----+---------+-------+
      | Field                                | Type            | Null | Key | Default | Extra |
      +--------------------------------------+-----------------+------+-----+---------+-------+
      | CAST(0xFFFFFFFFFF AS UNSIGNED)       | int(5) unsigned | NO   |     | NULL    |       |
      | CAST(0xFFFFFFFFFFFF AS UNSIGNED)     | int(6) unsigned | NO   |     | NULL    |       |
      | CAST(0xFFFFFFFFFFFFFF AS UNSIGNED)   | int(7) unsigned | NO   |     | NULL    |       |
      | CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED) | int(8) unsigned | NO   |     | NULL    |       |
      +--------------------------------------+-----------------+------+-----+---------+-------+
      

      Notice, it creates too small columns. All hex hybrids with more than 8 hexadecimal digits should create BIGINT columns.

      The same problem is repeatable for SIGNED type cast:

      These queries work fine:

      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFF AS SIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFF AS SIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFF AS SIGNED);
      

      These queries return the same error:

      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFF AS SIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFF AS SIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFFFF AS SIGNED);
      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFFFFFF AS SIGNED);
      

      ERROR 1264 (22003): Out of range value for column 'CAST(0xFFFFFFFFFFFFFF AS SIGNED)' at row 1
      

      This query works fine again:

      CREATE OR REPLACE TABLE t1 AS SELECT CAST(0xFFFFFFFFFFFFFFFF AS SIGNED);
      

        Attachments

          Issue Links

            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:
                  Resolved: