问题
i deleted 2000 row in my table and then i inserted same 2000 records but their index(id auto increment field) starting from 2001, now i want to update those index 2001 - 4000 to 1-2000
回答1:
To update your id run the following command.
UPDATE table SET id = id - 2000;
This will update the id of records in your table and then you need update the table's sequence
ALTER SEQUENCE table_id_seq RESTART WITH 2001;
This will allow you to insert the data with the id 2001
Another way, delete all the records from the table and update the sequence of the table and reinsert the data.
Hope this will be helpful.
来源:https://stackoverflow.com/questions/34718124/postgres-how-to-reset-or-update-indexsequence-of-table