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

RETURNING clause get the wrong last_insert_id() value

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not a Bug
    • 10.5.9
    • N/A
    • Server
    • None
    • centos

    Description

      Using RETURNING get the wrong last_insert_id(). I am not sure if this is a correct semantic.

      How to repeat:

      MariaDB [test]> create table t (id INT NOT NULL auto_increment, s varchar(255),primary key(id));
      Query OK, 0 rows affected (0.01 sec)
       
      MariaDB [test]> insert into t (s) values ("abc");
      Query OK, 1 row affected (0.00 sec)
       
      MariaDB [test]> select last_insert_id();
      +------------------+
      | last_insert_id() |
      +------------------+
      |                1 |
      +------------------+
      1 row in set (0.00 sec)
       
      MariaDB [test]> insert into t (s) values ("bcd") returning *, last_insert_id();
      +----+------+------------------+
      | id | s    | last_insert_id() |
      +----+------+------------------+
      |  2 | bcd  |                1 |
      +----+------+------------------+
      1 row in set (0.01 sec)
       
      MariaDB [test]> select last_insert_id();
      +------------------+
      | last_insert_id() |
      +------------------+
      |                2 |
      +------------------+
      1 row in set (0.00 sec)
       
      MariaDB [test]> 
      

      As we can see, we can't get the latest last_insert_id() using returning.

      Attachments

        Activity

          People

            Unassigned Unassigned
            lzch Zichao Lin
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.