Diagnostic Queries
Symptoms
A generate_series() call was given a step of zero. A zero step would never reach the end value, so PostgreSQL raises SQLSTATE 22023 (invalid_parameter_value).
- The step argument to
generate_seriesis 0. - A zero step would loop forever.
- Common with a computed step that can be zero.
What the server log shows
ERROR: step size cannot equal zero
Why PostgreSQL raises this — what the manual says
Section 9.25 Set Returning Functions:
“Generates a series of values from start to stop, with a step size of step.”
generate_series advances by step on each iteration. A zero step never progresses toward stop, which would be an infinite series, so PostgreSQL rejects it with 22023.
Common causes
- A literal step of 0.
- A computed step expression evaluating to 0.
- Variable step values not guarded against zero.
How to fix it
- Use a nonzero step (positive or negative as needed).
- Guard computed steps so they are never zero.
- Handle the single-value case separately when step would be zero.
Related & next steps
Reference: PostgreSQL 18 Section 9.25 “Set Returning Functions”.
Thanks — noted. This helps keep the database accurate.