SQLSTATE 22023 ERROR Class 22: Data Exception

invalid_parameter_value step size cannot equal zero — 22023

PostgreSQL error "step size cannot equal zero" (SQLSTATE 22023): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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_series is 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

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

Was this helpful?