SQLSTATE 22014Severity lowLab verified

Incident brief

ntile argument must be positive

The ntile(n) window function divides rows into n ranked buckets and requires n to be a positive integer; zero or a negative bucket count raises this data exception.

What lands in your log

ERROR: argument of ntile must be greater than zero

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What triggers it
Use ntile(n) OVER (...) with n set to zero or a negative value.
Fix
Pass a positive bucket count to ntile().
Proof
Reproduced on PostgreSQL 18.4 → A single windowed SELECT reproduces SQLSTATE 22014; ntile refuses the non-positive bucket count.

Fix

What to do right now

Application-level steps for this error.

  • Pass a positive bucket count to ntile().
  • Validate a dynamic bucket count (GREATEST(n, 1)) before it reaches the window function.
Fix SQL
-- ntile needs a positive number of buckets.
SELECT ntile(2) OVER (ORDER BY g) FROM generate_series(1,3) g;

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Verification scope
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops