Re: Ipv6 address stored differently while using Inet type

Поиск
Список
Период
Сортировка
От Peter J. Holzer
Тема Re: Ipv6 address stored differently while using Inet type
Дата
Msg-id 20181227134513.m2uzjpt7enxa6lqu@hjp.at
обсуждение исходный текст
Ответ на Ipv6 address stored differently while using Inet type  (Sameer Thakur <samthakur74@gmail.com>)
Список 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/>

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Sameer Thakur
Дата:
Сообщение: Ipv6 address stored differently while using Inet type
Следующее
От: Bhavin Gandhi
Дата:
Сообщение: Question about unlogged to logged conversion