Search code examples
postgresqlipv6

Ipv6 address stored differently while using Inet type Postgres 10.4


I tried to insert ipv6 address '2001:db8:3333:4444:5555:6666:1.2.3.4' in Postgres (10.4) in an inet column. It is stored as 2001:db8:3333:4444:5555:6666:102:304 Why is the IP stored differently? Does the stored IP represent the same one being inserted? Is this a known bug resolved in later versions of Postgres? regards Sameer


Solution

  • If you look closely you'll see that the address is exactly the same bit by bit. PostgreSQL is showing it to you in canonical format. The input you gave it (with the last 32 bits formatted as if they are an IPv4 address) is not the official representation.

    Take a look at RFC 5952.