RE: duplicate key value violates unique constraint
I have two immediate questions on this.
1)Do you Need to make sure there are no gaps in the sequence of id values?
2)Are you ever going to use 9223372036854775807 id values, even with the deletions?
If you want to re-use the id of a deleted row, and it is not going to cause problems elsewhere in your database, you could always have a deleted column in each row instead of actually removing from the table. When you want to insert next, you would just look for the first row where deleted is true and replace it.
Not entirely perfect, but would probably do the job.
From: Ashkar Dev [mailto:[hidden email]] Sent: 07 March 2020 19:35 To:[hidden email] Subject: Fwd: duplicate key value violates unique constraint
how to fix a problem, suppose there is a table with id and username
if I set the id to bigint so the limit is 9223372036854775807
if I insert for example 3 rows
if I delete all rows and insert one another it is like
So it doesn't start again from non-available id 1, so what is needed to do to make the new inserts go into non-available id numbers?
and if the id reaches the limit and maybe there is some ids that are not used.