Diagnostic Queries
Symptoms
A string given to the inet (or cidr) type was not a valid IP address/network. PostgreSQL raises SQLSTATE 22P02 (invalid_text_representation).
- The value is not a parseable IPv4/IPv6 address or CIDR.
- Common with malformed input, ranges, or extra characters.
- The message echoes the offending text.
What the server log shows
ERROR: invalid input syntax for type inet: "10.0.0.300"
Why PostgreSQL raises this — what the manual says
Section 8.9 Network Address Types:
“For example, 192.168.0.1/24 is valid for inet but not for cidr.”
The inet/cidr input functions validate the textual address and netmask. Text that does not parse as a valid address/network is rejected with 22P02.
Common causes
- An out-of-range octet or malformed address (e.g.
10.0.0.300). - Whitespace or stray characters in the value.
- Passing a hostname or range where an address is expected.
How to fix it
- Validate/normalize IP input in the application before insert.
- Use correct CIDR notation (e.g.
192.168.0.0/24). - Strip surrounding whitespace and verify each octet is 0–255.
Related & next steps
Reference: PostgreSQL 18 Section 8.9 “Network Address Types”.
Thanks — noted. This helps keep the database accurate.