Jake Rankin
Jake Rankin

Reputation: 744

How to have auto increment sequence in postgres increment by 4 instead of 1

I am using a command to change the number the auto increment sequence starts at for the id field:

ALTER SEQUENCE orders_order_id_seq RESTART 14028; 

I would like to make this increment by 4 instead of by 1. Is this possible?

I know this is a very short question but I don't have code examples I can provide for this. I have not found anything in the documentation or other questions that address this query.

Upvotes: 2

Views: 247

Answers (1)

Igor Borisenko
Igor Borisenko

Reputation: 3866

Yes, it is possible. Try

alter sequence orders_order_id_seq INCREMENT 4

PostgreSQL Documentation. ALTER SEQUENCE

increment The clause INCREMENT BY increment is optional. A positive value will make an ascending sequence, a negative one a descending sequence. If unspecified, the old increment value will be maintained.

Upvotes: 2

Related Questions