Postgres manually alter sequence

stef picture stef · Jan 5, 2012 · Viewed 196.6k times · Source

I'm trying to set a sequence to a specific value.

SELECT setval('payments_id_seq'), 21, true

This gives an error:

ERROR: function setval(unknown) does not exist

Using ALTER SEQUENCE doesn't seem to work either?

ALTER SEQUENCE payments_id_seq LASTVALUE 22

How can this be done?

Ref: https://www.postgresql.org/docs/current/static/functions-sequence.html

Answer

NPE picture NPE · Jan 5, 2012

The parentheses are misplaced:

SELECT setval('payments_id_seq', 21, true);  # next value will be 22

Otherwise you're calling setval with a single argument, while it requires two or three.