How to reset a sequence with PostgreSQL

2008-11-02 01:49:37 +0000

I would think that

1
2
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