Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RETURNING equivalent in MySQL

I need to find an equivalent in MySQL for the RETURNING functionality in PostgreSQL (for INSERT INTO). LAST_INSERT_ID() does not work because the id is not auto-incrementing, and is instead generated by a subquery. Because of the delay between the single queries allowed by PDO, I would like to implement this in a single line without table-locking so as to keep the table available.

like image 801
user1172452 Avatar asked Nov 05 '22 07:11

user1172452


1 Answers

How about to add a dummy auto-incremental primary key? Then, the process will not be done by single query, but can be done without explicit table-locking.

  1. Insert a row.
  2. Get PK via LAST_INSERT_ID().
  3. Fetch the row with result of [2].
like image 112
lqez Avatar answered Nov 07 '22 22:11

lqez