How to Fix “START value cannot be less than MINVALUE” When Creating a Sequence in PostgreSQL

In PostgreSQL, a sequence is a database object that is used to create a series of unique numeric values. However, when creating a sequence in Postgres, users may occasionally encounter an error stating that the “START value can’t be less than MINVALUE”. This error occurs at the time of sequence creation and the possible reason can be the start value is smaller than its minimum value.

This write-up illustrates how to solve the “START value can’t be less than MINVALUE” error in Postgres.

How to Fix the “START value can’t be less than MINVALUE” While Creating a Sequence in Postgres?

Encountering an error message like "START value can't be less than MINVALUE" while creating a sequence indicates that the sequence's starting value is smaller than the specified minimum value. Here is an example that demonstrates this error:

CREATE SEQUENCE cp_seq
MINVALUE 10
START 5;
img

To rectify this error, make sure that the starting value of the sequence is equal to or more/greater than the MINVALUE. For this purpose, either you can increment the start value or decrement the MINVALUE (or perform both tasks):

CREATE SEQUENCE cp_seq
MINVALUE 10
START 10;

In the following code example, setting the starting value of the sequence to be equal to the minimum value effectively resolves the mentioned issue:

img

This time the desired sequence has been successfully created. Type the following meta-command to view the sequence structure:

\d cp_seq;
img

That’s all about fixing the “START value can’t be less than MINVALUE” error in PostgreSQL.

Conclusion

In PostgreSQL, the “START value can’t be less than MINVALUE” error occurs at the time of sequence creation and the possible reason can be the start value is smaller than its minimum value. To fix this error, make sure that the starting value of the sequence is equal to or more/greater than the MINVALUE. For this purpose, either you can increment the start value or decrement the MINVALUE (or perform both tasks). This post has illustrated a complete process of fixing the “START value can’t be less than MINVALUE” error in PostgreSQL.