Re: Cleaning up the INET/CIDR mess

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: Cleaning up the INET/CIDR mess
Дата
Msg-id 874q3suvkq.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: Cleaning up the INET/CIDR mess  (Andrew - Supernews <andrew+nonews@supernews.com>)
Ответы Re: Cleaning up the INET/CIDR mess  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Andrew - Supernews <andrew+nonews@supernews.com> writes:

> If inet-to-cidr can zero out bits silently, then wouldn't making it an
> assignment cast be rather dangerous and error-prone?

The proposal was to make cidr-to-inet an implicit cast (happens automatically
without being requested) but make cidr-to-inet not implicit (you need to type
myinet::cidr or the "CAST" syntax to get it to happen).

Making the cast zero bits or making it error and having a separate function to
handle the conversion both seem entirely reasonable approaches.


I wonder if this would be an opportunity to fix Postgres's handling of
addresses like '10.1'. The standard interpretation of this is the same as
'10.0.0.1'. Currently Postgres interprets it as '10.1.0.0' for cidr and gives
an error for inet.

Perhaps if they become truly separate types then we could leave the cidr
behaviour alone since it is common to write things like 10.1/16 to refer to
the network prefix. But let inet have the standard interpretation.

It might be confusing but actually it's entirely logical. cidr is a type for
representing address ranges. '10.1/16'::cidr represents a range of addresses
from 10.1.0.0-10.1.255.255. There would be no reasonable use case for 10.0.0.1
in a cidr unless it was /32 which would refer to a specific address, in which
case it would make more sense to use an inet.

On the other hand '10.1'::inet represents a specific address and it's clear
which address it means -- it's even required to be interpreted this way by the
POSIX functions. Erroring out as Postgres currently does means applications
built on Postgres don't accept standard inernet address syntax.

-- 
greg



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Suggestions for post-mortem...
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Adding a --quiet option to initdb