# 2201G — invalid_argument_for_width_bucket_function

> Source-backed reference for PostgreSQL SQLSTATE 2201G.
---

# 2201G

## At a glance {#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.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| Field | Value |
| --- | --- |
| SQLSTATE | `2201G` |
| Condition | `invalid_argument_for_width_bucket_function` |
| Status | `active` |
| Known present by | `8.0.0` |
| Locked snapshots | `9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| Macros | `ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION` |
| Aliases | `—` |

<!-- source facts: data/errcodes/2201G.json -->
<!-- END SQLSTATE FACTS -->

## Representative messages {#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 {#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 {#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 {#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 {#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.

## Related {#related}
[`22003`](../22003/), [`22012`](../22012/)

## Sources {#sources}
The complete representative guards are in [`src/backend/utils/adt/numeric.c#L1959-2045`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/numeric.c#L1959) and [`src/backend/utils/adt/float.c#L4060-4180`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/float.c#L4060). The structured [evidence record](../data/evidence/2201g.json) retains all four primary templates and the bounded source scope; no natural runtime was run.
