Insert the lowest possible unique positve integer in an atomic fashion in MySql
Posted
by Jason Christa
on Stack Overflow
See other posts from Stack Overflow
or by Jason Christa
Published on 2010-04-14T19:17:42Z
Indexed on
2010/04/14
19:43 UTC
Read the original article
Hit count: 250
mysql
Say I have a table with a unique positive integer field. I currently have rows with id's of [1, 2, 3, 4, 5, 8, 12, 35]. Is there a insert query that I could write that would assign the id field to the lowest unique positive integer (in this case 6)? It would have to do this atomically so there isn't the possibility of concurrent inserts wiping out each other or failing.
© Stack Overflow or respective owner