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

Unexpected "BIGINT UNSIGNED value is out of range" for minus

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 10.1, 10.2, 10.3
    • Fix Version/s: 10.4
    • Component/s: None
    • Labels:
      None

      Description

      This script returns an error unexpectedly:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (
        c1 BIGINT UNSIGNED,
        c2 BIGINT UNSIGNED
      );
      INSERT INTO t1 VALUES (20030516235329,20000127231341);
      SELECT c2-c1 FROM t1;
      

      ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`test`.`t1`.`c2` - `test`.`t1`.`c1`)'
      

      It tries to create a BIGIN UNSIGNED column as a result:

      DROP TABLE IF EXISTS t2;
      CREATE TABLE t2 AS SELECT c2-c1 FROM t1 LIMIT 0;
      SHOW CREATE TABLE t2;
      

      +-------+-------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                          |
      +-------+-------------------------------------------------------------------------------------------------------+
      | t2    | CREATE TABLE `t2` (
        `c2-c1` bigint(21) unsigned DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+-------------------------------------------------------------------------------------------------------+
      

      The choice beween BIGINT and UNSIGNED BIGINT is controlled by the NO_UNSIGNED_SUBTRACTION flag in sql_mode.
      There should probably be a way to create a DECIMAL column instead.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated: