[FIXED] Postgres manually alter sequence

Issue

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/functions-sequence.html


Solution

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.

This is the same as SELECT setval('payments_id_seq', 21)



Answered By - NPE
Answer Checked By - Robin (sql.easybugfix Admin)

Related Posts

Post a Comment