Re: Ipv6 address stored differently while using Inet type

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Ipv6 address stored differently while using Inet type
Date: 2018-12-27 13:45:13
Message-ID: 20181227134513.m2uzjpt7enxa6lqu@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)hjp(dot)at | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bhavin Gandhi 2018-12-27 22:23:44 Question about unlogged to logged conversion
Previous Message Sameer Thakur 2018-12-27 09:26:25 Ipv6 address stored differently while using Inet type