5

The Postgres documentation CREATE TABLE says for GENERATED BY DEFAULT AS IDENTITY (sequence_options) that:

The optional sequence_options clause can be used to override the options of the sequence. See CREATE SEQUENCE for details.

The documentation CREATE SEQUENCE no longer calls them as options but parameters. Anyway, the name is also listed as a parameter. The examples are rather taciturn. Is it possible to override the name of the sequence that will be created for an identity column?

1 Answer 1

5

It turned out the answer is yes, there is a way. The twist is that while it is obvious you're giving sequence options between the parenthesis, simply saying NAME xyz is not enough, you still have to tell postgres that the name you provide is SEQUENCE NAME:

CREATE TABLE test(
    i int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY(SEQUENCE NAME xyz START WITH 1)
) ;
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.