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

INSERT ... RETURNING missing lastInsertId in response package

    XMLWordPrintable

Details

    Description

      Given a simple autoincrement table:

      CREATE TABLE InsertIdTest (
          id        INT NOT     NULL AUTO_INCREMENT,
          one       VARCHAR(45) NULL,
          PRIMARY KEY (id)
      )
      

      an insert query returns the lastInsertId in the response package so it's accessible by clients:

      INSERT INTO InsertIdTest (one) VALUES ("Hello World")
      

      but inserting data with a INSERT ... RETURNING doesn't return the lastInsertId:

      INSERT INTO InsertIdTest (one) VALUES ("Bye Bye") RETURNING *
      

      Instead afterwards either the lastInsertId has to be extracted from the returned resultset, which not neccessarily must include the ID column, or an additional query to select the lastInsertId has to be executed.

      compare PHP PDO client issue: https://github.com/php/php-src/issues/11503

      Attachments

        1. MDEV-31560.pcapng
          29 kB
          Daniel Black
        2. screenshot-1.png
          70 kB
          Daniel Black
        3. screenshot-2.png
          103 kB
          Daniel Black

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              wol-soft Enno Woortmann
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.