22023
PostgreSQLERRORNotableData ExceptionHIGH confidence
invalid parameter value
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
trigger — this will error
SELECT REPEAT('x', -1);expected output
ERROR: invalid parameter value for REPEAT: -1
Fix
Validate parameter values before calling the function
WHEN When parameter values come from user input or computed expressions.
Validate parameter values before calling the function
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 documentation ↗
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev