step size cannot equal zero

SQLSTATE 22023 condition invalid_parameter_value class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

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).

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

How to fix it

  1. Use a nonzero step (positive or negative as needed).
  2. Guard computed steps so they are never zero.
  3. Handle the single-value case separately when step would be zero.

Related & next steps

Reference: PostgreSQL 18 Section 9.25 “Set Returning Functions”.