Skip to content

2202G — invalid_tablesample_repeat

Source-backed reference for PostgreSQL SQLSTATE 2202G.

2202G

At a glance

The TABLESAMPLE REPEATABLE seed is invalid when it is NULL. The fixed executor path reports TABLESAMPLE REPEATABLE parameter cannot be null.

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

Messages

The executor guard uses this primary text:

Guard Primary
NULL REPEATABLE expression TABLESAMPLE REPEATABLE parameter cannot be null

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

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

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

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.

2202H, 22004

Sources

The executor evaluates method arguments and then the optional repeat expression in src/backend/executor/nodeSamplescan.c#L232-267. The structured evidence record retains the 2202G guard and its boundary with 2202H; no natural runtime was run.