is there a way to reset the primary key of a postgres table to start at 1 again on a populated table?
right now its generating numbers from 1000000 and up. I want it all to reset and start to 1, keeping all my existing data intact.
Thanks.
is there a way to reset the primary key of a postgres table to start at 1 again on a populated table?
right now its generating numbers from 1000000 and up. I want it all to reset and start to 1, keeping all my existing data intact.
Thanks.
Primary keys that autoincrement (i.e., columns with data type serial primary key
) are associated with a sequence. You can set the next value for any sequence using setval(<seqname>,<next_value>)
.
The name of the auto created sequences when using serial are <table>_<column>_seq
What's the point? It's just a number without any meaning. You could update all records and all related data in all other tables. You also have to reset all sequences.
Be careful with your backups as well, older backups hold very different data!
Don't waste your time getting nowhere.