Restart PostgreSQL sequence – how to?

I thought this would work:

ALTER SEQUENCE users_id_seq  RESTART WITH (SELECT MAX(id) FROM users);

but it doesn’t! :O It throws “ERROR:  syntax error at or near “select” “!

If you have this problem, try the other approach:

SELECT SETVAL(‘users_id_seq’,(SELECT MAX(id) FROM users));

Tested on version 8.4.0, on FreeBSD 8.0…

Advertisement

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.