i have this PostgreSQL table
---------------------------------
| id | tag | name |
---------------------------------
| 1 | 1 | name1 |
| 3 | 3 | name3 |
| 4 | 4 | name4 |
| 6 | 6 | name6 |
| 7 | 7 | name7 |
this table hold customer numbers : id is auto increment primary key. tag is a unique integer ,it act as an easy way to find a person in the database . because of some practical issues ,persons regularly leave the area and never comes again. total number of customers never exceed 200 at any given time but there is relatively rapid turn over. because tag number is entered manually in the program and has to be memorized by customers ,i want to keep the tag number very small so when i delete one customer i want to reuse its tag number.
in the table above customer with id #2 and 5 was deleted some time ago. now i am about to insert a new customer , and want the database to find for me the lowest tag number available (in this case it will be #2) so that i can reuse it for the next customer.
how ?
latest NpgSQL 3.0.5 and PostgreSQL 9.5