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

last_insert_id() returns a signed number

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.5.24, 5.3.7, 5.2.12, 5.1.62
    • Fix Version/s: 5.5.25
    • Component/s: None
    • Labels:
      None

      Description

      Test case

      create table t1 (a bigint unsigned auto_increment primary key);
      insert into t1 values((1<<63)-2);
      insert into t1 values(NULL); select last_insert_id();
      insert into t1 values(NULL); select last_insert_id();
      select * from t1;
      

      Result

      MariaDB [test]> insert into t1 values(NULL); select last_insert_id();
      +---------------------+
      | last_insert_id()    |
      +---------------------+
      | 9223372036854775807 |
      +---------------------+
      MariaDB [test]> insert into t1 values(NULL); select last_insert_id();
      +----------------------+
      | last_insert_id()     |
      +----------------------+
      | -9223372036854775808 |
      +----------------------+
      MariaDB [test]> select * from t1;
      +---------------------+
      | a                   |
      +---------------------+
      | 9223372036854775806 |
      | 9223372036854775807 |
      | 9223372036854775808 |
      +---------------------+
      

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            monty Michael Widenius added a comment -

            Fixed by making last_insert_id() unsigned

            Show
            monty Michael Widenius added a comment - Fixed by making last_insert_id() unsigned

              People

              • Assignee:
                monty Michael Widenius
                Reporter:
                serg Sergei Golubchik
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 15 minutes
                  15m