0

I would like to make a script in PostgreSQL to create a sequence for a table. I would like to put maximum value of another sequence as a min value of this new one. I'm trying to do this like:

create sequence test
INCREMENT 1
MINVALUE SELECT max (id) from test_table

Also I've tried:

create sequence test
INCREMENT 1
MINVALUE SELECT nextval('old_seq')

Is it even possible to do this at the point of creation?

1 Answer 1

1

Use setval() after creating the sequence:

create sequence test INCREMENT 1;
select setval('test', nextval('old_seq'));
Sign up to request clarification or add additional context in comments.

Comments

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.