SQLSTATE 22P02 ERROR Class 22: Data Exception

invalid_text_representation invalid input syntax for type inet: “…” — 22P02

PostgreSQL error "invalid input syntax for type inet: "…"" (SQLSTATE 22P02): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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

  1. Validate/normalize IP input in the application before insert.
  2. Use correct CIDR notation (e.g. 192.168.0.0/24).
  3. Strip surrounding whitespace and verify each octet is 0–255.

Related & next steps

Reference: PostgreSQL 18 Section 8.9 “Network Address Types”.

Was this helpful?