How to reset a sequence with PostgreSQL
November 3rd, 2008
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
Posted by mikel
Filed in
Recent Articles
Latest comments
- Adam Milligan
I’d like to see a method in the TMail::Address interface that provides validation without depending on exception handling.
- Mikel
Hey Brian,
Thanks for the suggestion, kibitz looks perfect!
Mikel
- Brian Fox
I highly recommend using “kibitz” instead. You can find this program as part of the TCL “expect” package.
Kibitz...
- Tudor Constantin
This was a great help. Small, concise, exactly what I needed. Thx alot
- Gianni
How to use it in error_messages_for ???
- wictor
I have moved TMail onto GIT too.
Leave a Reply