Re: Ipv6 address stored differently while using Inet type - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: Ipv6 address stored differently while using Inet type
Date
Msg-id 20181227134513.m2uzjpt7enxa6lqu@hjp.at
Whole thread Raw
In response to Ipv6 address stored differently while using Inet type  (Sameer Thakur <samthakur74@gmail.com>)
List pgsql-general
On 2018-12-27 14:56:25 +0530, Sameer Thakur wrote:
> I am using 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.

No. It is *displayed* as "2001:db8:3333:4444:5555:6666:102:304". It is
stored as a 128 bit sequence.

> Why is the IP stored differently?

It is displayed in the way IPv6 addresses are usually displayed (16 bit
groups in hex separated by colons). The form you used to insert the
address (first 96 bits in hex and last 32 bits in decimal) is normally
only used for the IPv4 compatibility range: You would write
0000:0000:0000:0000:0000:0000:C000:022A as ::192.0.2.42, not ::C000:22A,
but you would write 2001:db8:3333:4444:5555:6666:102:304, not
2001:db8:3333:4444:5555:6666:1.2.3.4.

> Does the stored IP represent the same one being inserted?

Yes.

>  Is this a known bug resolved in later versions of Postgres?

No.

        hp

--
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>

Attachment

pgsql-general by date:

Previous
From: Sameer Thakur
Date:
Subject: Ipv6 address stored differently while using Inet type
Next
From: Bhavin Gandhi
Date:
Subject: Question about unlogged to logged conversion