How to reset a sequence with PostgreSQL
2 November 2008
I would think that
ALTER SEQUENCE sequence_name
RESTART WITH (SELECT max(id) FROM table_name);
would work, but it doesn’t. Use:
SELECT SETVAL('sequence_name', (SELECT MAX(id) FROM table_name) + 1);
instead and you will be a lot more happier.
blogLater
Mikel