in reply to Cycle through primary key with DBI
Then when you want to insert into your table, you'll first need to lock the control table (or just the record, I'm not sure if a table lock attempt will block or immediately fail in PostgreSQL, either way you could work it out) select the 'next' id number from the control table, update the control table, unlock the control table, delete from your table, then insert into your table. I'd probably do this all in a transaction so we can rollback if any of it fails.
I'd just do the 'delete' from your table every time, because soon you'll have your thousand records and it won't be worth checking to see if you 'should' delete.
|
|---|