0

I am trying to alter database sequence and restart it with value returned by complex SELECT statement. This is a simplified example that I prepared to replicate the issue:

ALTER SEQUENCE
    abc.my_seq
RESTART WITH
    (SELECT 1234)

When I run this query, I get the following error:

ERROR: syntax error at or near "("

Why am I receiving this error? Is it possible to set the value of a sequence based on returned value of SELECT statement?

0

1 Answer 1

2

You can use setval() instead

select setval('abc.my_seq', (select ... 
                             from ...));

Note the parentheses around the select.

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

2 Comments

Thank you, this works. Is there a reason why my initial try (ALTER SEQUENCE abc.my_seq RESTART WITH (SELECT 1234)) doesn't work? Is it simply not allowed by-design in PostgreSQL?
DDL statements typically do not allow parameters to be specified by queries

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.