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

GREATEST incorrectly checks a fields' datatype during calculations

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.2.14
    • N/A
    • Data types
    • None
    • Linux CentOS 7 64 bit

    Description

      If a field is created with :
      fieldname SMALLINT UNSIGNED DEFAULT 0

      Then using

      GREATEST(0, fieldname-1)

      in SELECT or UPDATE
      will trigger an error and not give results
      ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '`db`.`table`.`fieldname` - 1'

      Actual example for SELECT:

      select greatest(1,loc_count-1) from Custom_Lists;
      ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '`pj_dev`.`Custom_Lists`.`loc_count` - 1'

      same for UPDATE

      The error should only be triggered in a direct field,not using GREATEST()

      Attachments

        Issue Links

          Activity

            This script demonstrates the problem:

            CREATE OR REPLACE TABLE t1 (a SMALLINT UNSIGNED);
            INSERT INTO t1 VALUES (0);
            SELECT GREATEST(0, a-1) FROM t1;
            

            bar Alexander Barkov added a comment - This script demonstrates the problem: CREATE OR REPLACE TABLE t1 (a SMALLINT UNSIGNED); INSERT INTO t1 VALUES (0); SELECT GREATEST(0, a-1) FROM t1;

            Also repeatable with COALESCE:

            CREATE OR REPLACE TABLE t1 (a SMALLINT UNSIGNED);
            INSERT INTO t1 VALUES (0);
            SELECT COALESCE(a-1,0) FROM t1;
            

            bar Alexander Barkov added a comment - Also repeatable with COALESCE : CREATE OR REPLACE TABLE t1 (a SMALLINT UNSIGNED); INSERT INTO t1 VALUES (0); SELECT COALESCE (a-1,0) FROM t1;

            Also repeatable with just subtraction:

            CREATE OR REPLACE TABLE t1 (a SMALLINT UNSIGNED);
            INSERT INTO t1 VALUES (0);
            SELECT a-1 FROM t1;
            

            bar Alexander Barkov added a comment - Also repeatable with just subtraction: CREATE OR REPLACE TABLE t1 (a SMALLINT UNSIGNED); INSERT INTO t1 VALUES (0); SELECT a-1 FROM t1;

            This is expected behavior.

            Please use:

            SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';
            

            to get a signed result.

            https://mariadb.com/kb/en/library/sql-mode/
            https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_unsigned_subtraction

            bar Alexander Barkov added a comment - This is expected behavior. Please use: SET sql_mode = 'NO_UNSIGNED_SUBTRACTION' ; to get a signed result. https://mariadb.com/kb/en/library/sql-mode/ https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_unsigned_subtraction

            People

              bar Alexander Barkov
              laxamar Jacques Amar
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.