1

How can I update the last_value field in my sequence and add 1 to it?

table

The query I tried: ALTER SEQUENCE "seq_hours" SET 'last_value' = 'last_value' + 1

However this did not work.

1 Answer 1

1

Use setval() with a subquery to get the value from a table, e.g.

SELECT setval('seq_hours', (SELECT max(last_value)+1 FROM t));

EDIT: This solution only makes sense if you want to set the current value of a sequence based on a value from a given table. If you only want the next possible value of a sequence you should use nextval as @a_horse_with_no_name suggested (see comments)

Sign up to request clarification or add additional context in comments.

1 Comment

@yesIamFaded or simply select nextval('seq_hours')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.