PostgreSQLERROR 22P02
PostgreSQL: Invalid Input Syntax for Type Integer
PostgreSQL 22P02 is raised when a string cannot be cast to the target numeric type. PostgreSQL's strict type system requires explicit casts unlike MySQL's implicit conversion.
Example Query
SELECT * FROM orders WHERE id = 'abc'; -- 'abc' cannot be cast to integer
Common Causes
- 1Passing a non-numeric string where an integer is expected
- 2URL parameter not validated before use in query
- 3Empty string passed for a numeric column
How to Fix It
Validate and parse request parameters before using in queries. Use parameterised queries — the driver handles type conversion. Add an explicit cast with error handling: CAST(value AS integer) or use CASE WHEN value ~ '^[0-9]+$' THEN value::integer END.
Need a reliable database?
Try Supabase — free PostgreSQL with a generous free tier. No credit card required.
Got a query causing this error?
Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.
Analyze My Query →