If you’re getting an error that reads something like “START value (0) cannot be less than MINVALUE (1)” in PostgreSQL when you’re trying to create a sequence, it’s because your sequence’s start value is lower than its minimum value, when it should be at least the same or higher.
To fix this issue, be sure that the sequence’s start value is at least the same or greater than the minimum value.
Example of Error
Here’s an example of code that produces the error:
CREATE SEQUENCE Sequence1
MINVALUE 1
START 0;
Result:
ERROR: START value (0) cannot be less than MINVALUE (1)
Here, my START
value is 0
but my MINVALUE
is 1
, which is higher than the start value, and so an error occurred.
Solution
To fix this issue, we can either increase the start value, decrease the minimum value, or do both.
Here’s an example of increasing the START
value:
CREATE SEQUENCE Sequence1
MINVALUE 1
START 1;
Result:
Commands completed successfully
In this case I increased the START
value by one, so that it’s the same value as MINVALUE
. The code ran without error, and my client told me that the command completed successfully.
Alternatively, we could have reduced the MINVALUE
value. Or we could have done both – increased the START
while decreasing the MINVALUE
value.