PG
PRO
2202HERRORTier 2 — Caution✅ HIGH confidence

invalid tablesample argument

Category: Data ExceptionVersions: Postgres 9.5+

What this means

SQLSTATE 2202H is raised when a TABLESAMPLE clause receives an invalid argument — for example, a sampling percentage outside the range 0–100 for BERNOULLI or SYSTEM sampling.

Why it happens

  1. 1Using a sampling percentage less than 0 or greater than 100 in TABLESAMPLE BERNOULLI or TABLESAMPLE SYSTEM

How to reproduce

TABLESAMPLE with an invalid percentage.

trigger — this will ERROR
SELECT * FROM large_table TABLESAMPLE BERNOULLI(150);
ERROR: sample percentage must be between 0 and 100

Fix 1: Use a sampling percentage between 0 and 100

When using TABLESAMPLE for random sampling.

fix
SELECT * FROM large_table TABLESAMPLE BERNOULLI(10); -- 10% sample

Why this works

The BERNOULLI and SYSTEM methods require a percentage in [0, 100]. Values outside this range cause 2202H.

Version notes

Postgres 9.5+TABLESAMPLE syntax introduced in 9.5.

Sources

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE for TABLESAMPLE argument validation. Stable since 9.5.

See also

📄 Reference pages

TABLESAMPLESELECT FROM
⚙️ 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 →