Fix “START value (…) cannot be greater than MAXVALUE (…)” When Creating a Sequence in PostgreSQL

If you’re getting an error that reads something like “START value (11) cannot be greater than MAXVALUE (10)” in PostgreSQL when you’re trying to create a sequence, it’s because your sequence’s start value is higher than its maximum value, when it should be lower or the same.

To fix this issue, be sure that the sequence’s maximum value is not less than its start value.

Example of Error

Here’s an example of code that produces the error:

CREATE SEQUENCE Sequence1
    MINVALUE 0
    MAXVALUE 10
    START 11;

Result:

ERROR:  START value (11) cannot be greater than MAXVALUE (10)

Here, my START value is 11 but my MAXVALUE is only 10. We can’t create a sequence with a higher start value than its maximum value, and so an error occurred.

Solution

To fix this issue, we can either decrease the start value, increase the maximum value, or do both.

Here’s an example of decreasing the START value:

CREATE SEQUENCE Sequence1
    MINVALUE 0
    MAXVALUE 10
    START 1;

Result:

Commands completed successfully

In this case I decreased the START value to 1 so that it’s lower than the MAXVALUE. The code ran without error, and my client told me that the command completed successfully.

Alternatively, we could have increased the MAXVALUE value to a much higher value. Or we could have done both – decreased the START while increasing the MAXVALUE value.