22023ERRORTier 2 — Caution✅ HIGH confidenceinvalid parameter value
Category: Data ExceptionVersions: All Postgres versions
What this means
SQLSTATE 22023 is raised when a function or command receives a parameter value that is syntactically valid but semantically out of range or logically invalid. It is a broad code used across many built-in functions.
Why it happens
- 1Passing an out-of-range value to a function that imposes semantic constraints on its arguments
- 2Supplying a negative or zero value where only positive values are accepted
- 3Providing a string that does not match the expected format for a parameter
How to reproduce
Calling REPEAT with a negative count.
trigger — this will ERROR
SELECT REPEAT('x', -1);ERROR: invalid parameter value for REPEAT: -1
Fix 1: Validate parameter values before calling the function
When parameter values come from user input or computed expressions.
fix
SELECT REPEAT('x', GREATEST(count_val, 0)) FROM data;Why this works
GREATEST clamps the value to the minimum valid range, preventing 22023.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 22 — Data Exception
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE used broadly by Postgres built-in functions. Stable across versions.
See also
🔗 Related errors
📄 Reference pages
String FunctionsMathematical Functions
⚙️ 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 →