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

ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL)
    • 10.2.16, 10.3.8, 10.4.0
    • OTHER
    • None

    Description

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a DECIMAL(30,0));
      INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
      SELECT * FROM t1;

      returns

      +----------------------+
      | a                    |
      +----------------------+
      | 18446744073709551615 |
      +----------------------+

      So far so good.

      Now if I do:

      ALTER TABLE t1 MODIFY a BIGINT UNSIGNED;
      SELECT * FROM t1;

      it erroneously returns:

      +---------------------+
      | a                   |
      +---------------------+
      | 9223372036854775807 |
      +---------------------+

      The expected result is 18446744073709551615.

      Attachments

        Issue Links

          Activity

            The same problem is repeatable with BIT(64)

            SET sql_mode='';
            DROP TABLE IF EXISTS t1;
            CREATE TABLE t1 (a DECIMAL(30,0));
            INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
            ALTER TABLE t1 MODIFY a BIT(64);
            SHOW WARNINGS;
            SELECT a+0 FROM t1;
            

            +---------+------+-----------------------------------------------------------------------------+
            | Level   | Code | Message                                                                     |
            +---------+------+-----------------------------------------------------------------------------+
            | Warning | 1916 | Got overflow when converting '18446744073709551615' to INT. Value truncated |
            +---------+------+-----------------------------------------------------------------------------+
            

            +---------------------+
            | a+0                 |
            +---------------------+
            | 9223372036854775807 |
            +---------------------+
            

            bar Alexander Barkov added a comment - The same problem is repeatable with BIT(64) SET sql_mode= '' ; DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a DECIMAL (30,0)); INSERT INTO t1 VALUES ( CAST (0xFFFFFFFFFFFFFFFF AS UNSIGNED)); ALTER TABLE t1 MODIFY a BIT (64); SHOW WARNINGS; SELECT a+0 FROM t1; +---------+------+-----------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------------------------------------------+ | Warning | 1916 | Got overflow when converting '18446744073709551615' to INT. Value truncated | +---------+------+-----------------------------------------------------------------------------+ +---------------------+ | a+0 | +---------------------+ | 9223372036854775807 | +---------------------+

            People

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