6 Ways to Fix “nextval: reached minimum value of sequence” in PostgreSQL

If you’re getting an error that reads something like “nextval: reached minimum value of sequence “sequence1” (-3)” in PostgreSQL, it’s probably because you’re trying to generate a new value from a descending sequence, but the sequence has already reached its minimum value.

We have a number options when it comes to dealing with this issue.

Continue reading

Fix “ERROR:  step size cannot equal zero” When Creating a PostgreSQL Series

If you’re getting an error that reads “step size cannot equal zero” when creating a series with the generate_series() function in PostgreSQL, it’s because you’re using a step size of 0 (i.e. zero).

The generate_series() function doesn’t accept a zero step size.

To fix this issue, either use a non-zero step size, or remove the step size altogether (so that the default step is used).

Continue reading

Fix “MINVALUE (…) must be less than MAXVALUE (…)” When Creating a Sequence in PostgreSQL

If you’re getting an error that reads something like “MINVALUE (1) must be less than MAXVALUE (1)” in PostgreSQL when you’re trying to create a sequence, it’s probably because your sequence’s minimum possible value is higher than the maximum value.

To fix this issue, be sure that the sequence’s maximum value is greater than the minimum value.

Continue reading

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 (101) cannot be greater than MAXVALUE (100)” in PostgreSQL when you’re trying to create a sequence, it’s probably because your sequence’s maximum possible value is lower than the start value.

To fix this issue, change either the start value or maximum value so that the maximum value is greater than the start value.

Continue reading

Fix “cannot insert into column… Column is an identity column defined as GENERATED ALWAYS” in PostgreSQL

If you’re getting an error in PostgreSQL that reads something like “cannot insert into column” with detail that explains that the “…is an identity column defined as GENERATED ALWAYS“, it’s probably because you’re trying to insert your own value into an identity column that was created with the GENERATED ALWAYS option, but you’re not explicitly overriding the column from auto generating its own value.

To fix this issue, use OVERRIDING SYSTEM VALUE when inserting the value.

Continue reading

6 Ways to Fix “nextval: reached maximum value of sequence” in PostgreSQL

If you’re getting an error that reads something like “nextval: reached maximum value of sequence “sequence1” (3)” in PostgreSQL, it’s probably because you’re trying to generate a new value from a sequence, but the sequence has already reached its maximum value.

We have quite a few options when it comes to dealing with this issue.

Continue reading

Fix “lastval is not yet defined in this session” When Calling the LASTVAL() Function in PostgreSQL

If you’re getting an error that reads something like “lastval is not yet defined in this session” when calling the lastval() function in PostgreSQL, it’s probably because nextval() hasn’t yet been called in the current session.

If you want to avoid this error, only call the lastval() function when you know that nextval() has been called at least once in the current session.

Continue reading