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.
Share
I would not use this to fill up “missing” ids, but this should work:
Get all
ids whereid + 1does not exist (Left Join), and insertMin(id)+1or0if non is available.