PG
PRO
2202GERRORTier 2 — Caution✅ HIGH confidence

invalid tablesample repeat

Category: Data ExceptionVersions: Postgres 9.5+

What this means

SQLSTATE 2202G is raised when the REPEATABLE seed value passed to a TABLESAMPLE clause is invalid.

Why it happens

  1. 1Passing an out-of-range or NULL seed value to TABLESAMPLE BERNOULLI(p) REPEATABLE(seed)

How to reproduce

TABLESAMPLE with an invalid REPEATABLE seed.

trigger — this will ERROR
SELECT * FROM orders TABLESAMPLE SYSTEM(10) REPEATABLE(NULL);
ERROR: tablesample_repeat must not be null

Fix 1: Provide a valid non-NULL numeric seed to REPEATABLE

When reproducible sampling is needed.

fix
SELECT * FROM orders TABLESAMPLE SYSTEM(10) REPEATABLE(42);

Why this works

The REPEATABLE seed must be a non-NULL numeric value. The same seed produces the same sample across runs (for SYSTEM method).

Version notes

Postgres 9.5+TABLESAMPLE and REPEATABLE introduced in 9.5.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class 22 — Data Exception

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE for TABLESAMPLE REPEATABLE validation. Stable since 9.5.

See also

📄 Reference pages

TABLESAMPLEREPEATABLE
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →