PostgreSQL raises invalid_tablesample_repeat (SQLSTATE 2202G) when the REPEATABLE seed in a TABLESAMPLE clause is missing, not an integer, or outside the 0-2147483647 range.
PostgreSQL invalid_tablesample_repeat (SQLSTATE 2202G) appears when the REPEATABLE seed in a TABLESAMPLE clause is absent, non-integer, or out of range. Supply a valid 32-bit integer to REPEATABLE or drop the clause to resolve the error.
PostgreSQL Error 2202G
PostgreSQL throws SQLSTATE 2202G – invalid_tablesample_repeat – when it parses a TABLESAMPLE clause whose REPEATABLE() argument is not a valid 32-bit integer literal.
The planner cannot guarantee deterministic sampling without a stable numeric seed, so it aborts and returns this error instead of running an unpredictable query.
PostgreSQL expects REPEATABLE(seed) to contain a single integer in the range 0 to 2147483647.
Any deviation raises invalid_tablesample_repeat.
Using an expression, passing a float, null, negative, or over-large value, or omitting the seed entirely are the most common triggers.
Rewrite the TABLESAMPLE clause so that REPEATABLE receives a hard-coded integer between 0 and 2147483647.
If deterministic sampling is not needed, remove the REPEATABLE clause altogether.
Always validate user-supplied seeds before concatenating them into dynamic SQL.
Dynamic SQL seed from UI – Cast or validate the input and clamp it to the valid range before string interpolation.
Migrated query from another DBMS – Other systems allow floats.
Replace with an integer or drop REPEATABLE.
Parameterize REPEATABLE seeds with $1
placeholders and check the value in application code.
Add unit tests for analytic queries that rely on TABLESAMPLE to ensure seeds remain integers after refactors.
2202H invalid_tablesample_argument – Raised when TABLESAMPLE percentage is bad. Supply a numeric between 0 and 100.
42601 syntax_error – Triggered by misplaced REPEATABLE keyword. Follow the TABLESAMPLE method list precisely.
.
No. Omitting REPEATABLE performs non-deterministic sampling, which is fine for exploratory queries.
Any 32-bit signed integer from 0 to 2147483647.
Yes. Use prepared statements or named parameters and pass an integer value at runtime.
Galaxy's SQL linter flags non-integer REPEATABLE seeds as you type, preventing the error before execution.