select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 22 · DATA EXCEPTION

invalid_argument_for_width_bucket_function

SQLSTATE
2201G
Condition name
invalid_argument_for_width_bucket_function
Class
Data Exception
Source macro
ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>2201G</h1>

At a glance

width_bucket validates its bucket count, NaN inputs, histogram bounds, and bound equality. The fixed numeric and float8 paths report distinct 2201G messages for non-positive count, NaN, non-finite bounds, and equal bounds.

Representative messages

The fixed guards use these primary texts:

Guard Primary
non-positive count count must be greater than zero
any NaN operand or bound operand, lower bound, and upper bound cannot be NaN
non-finite bound lower and upper bounds must be finite
equal bounds lower bound cannot equal upper bound

Meaning

For the numeric and float8 width_bucket(operand, bound1, bound2, count) signatures, count must be greater than zero; operand or either bound cannot be NaN; and both bounds must be finite and unequal. The implementation accepts either ascending or descending bounds, and an infinite operand is allowed even though an infinite bound is not. If a valid endpoint calculation overflows count + 1, the source reports 22003 instead.

Diagnosis

Use the function signature and the exact primary message to identify the offending argument. Check count, then distinguish NaN from infinity and distinguish the operand from the two bounds. Do not impose a lower-than-upper rule: descending bounds have their own valid bucket calculation. An equal pair is the specific ordering failure covered by 2201G.

Response

Correct the named count, operand, or bound while preserving the intended bucket direction. Keep both bounds finite and unequal, use a positive count, and handle an out-of-range result as the separate 22003 condition. If this ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected call.

Versions

The locked catalogue records this condition from 8.0.0; the fixed source paths here are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

Sources

The complete representative guards are in src/backend/utils/adt/numeric.c#L1959-2045 and src/backend/utils/adt/float.c#L4060-4180. The structured evidence record retains all four primary templates and the bounded source scope; no natural runtime was run.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

2201G is invalid_argument_for_width_bucket_function in SQLSTATE Class 22

Method: Read the fixed errcodes row and macro.

src.errcodes.18.6

Fixed PostgreSQL 18.6 numeric and float8 width_bucket paths bind count, NaN, finite-bound, unequal-bound, ascending, descending, and operand-infinity behavior.

Method: Read complete source contexts for the representative guards.

Limits: Source confirmation is not a natural runtime observation.

src.numeric.width_bucket src.float.width_bucket

The locked catalogue records 2201G from 8.0.0 without proving an exact implementation introduction date.

Method: Use catalogue presence and history boundaries.

src.errcodes.18.6

Valid endpoint arithmetic can raise the distinct 22003 integer-out-of-range condition when count plus one exceeds int4.

Method: Read the result conversion/overflow branch, not the 2201G guards.

src.numeric.width_bucket src.float.width_bucket

Message templates

ERROR · message.count

Primary

count must be greater than zero
ERROR · message.nan

Primary

operand, lower bound, and upper bound cannot be NaN
ERROR · message.bounds-finite

Primary

lower and upper bounds must be finite
ERROR · message.bounds-equal

Primary

lower bound cannot equal upper bound

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:14a40a989fd6137edd1a2f05b3c… · English manual source