# 2202G — invalid_tablesample_repeat

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

# 2202G

## At a glance {#at-a-glance}
The TABLESAMPLE REPEATABLE seed is invalid when it is NULL. The fixed executor path reports `TABLESAMPLE REPEATABLE parameter cannot be null`.

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

| Field | Value |
| --- | --- |
| SQLSTATE | `2202G` |
| Condition | `invalid_tablesample_repeat` |
| Status | `active` |
| Known present by | `9.5.0` |
| Locked snapshots | `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_TABLESAMPLE_REPEAT` |
| Aliases | `—` |

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

## Messages {#messages}
The executor guard uses this primary text:

| Guard | Primary |
| --- | --- |
| NULL `REPEATABLE` expression | `TABLESAMPLE REPEATABLE parameter cannot be null` |

## Meaning {#meaning}
During `tablesample_init`, PostgreSQL evaluates each TABLESAMPLE method argument first and reports 2202H when one is NULL. It then evaluates the optional `REPEATABLE` expression separately; a NULL result takes the 2202G branch. A non-NULL REPEATABLE value has already been coerced to `float8` by the parser and is hashed with `hashfloat8` to make the sampling seed. This code therefore covers the repeat-seed NULL contract, not a negative seed or a method percentage range.

## Diagnosis {#diagnosis}
Inspect the evaluated `REPEATABLE` expression, including a parameter or function that may become SQL NULL. Keep it separate from a NULL TABLESAMPLE method argument, which uses 2202H, and from a non-NULL but invalid percentage, size, or time argument, which is checked by the selected sampling method. The primary text identifies the repeat-seed branch.

## Response {#response}
Supply a non-NULL expression to `REPEATABLE`, or omit the clause when deterministic repetition is not required. Correct the method argument separately if its own 2202H guard fires. If an ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected statement.

## Versions {#versions}
The locked catalogue records this condition from 9.5.0; the fixed source path here is PostgreSQL 18.6. No natural runtime observation is claimed for this page.

## Related {#related}
[`2202H`](../2202h/), [`22004`](../22004/)

## Sources {#sources}
The executor evaluates method arguments and then the optional repeat expression in [`src/backend/executor/nodeSamplescan.c#L232-267`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeSamplescan.c#L232). The structured [evidence record](../data/evidence/2202g.json) retains the 2202G guard and its boundary with 2202H; no natural runtime was run.
