Skip site navigation (1) Skip section navigation (2)

Repair plan for inet and cidr types

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Repair plan for inet and cidr types
Date: 2000-07-05 00:12:35
Message-ID: Pine.LNX.4.21.0007050118110.3542-100000@localhost.localdomain (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
As we know, the inet and cidr types are still broken in several ways,
amongst others input and output functions, operators, ordering. I've
collected the bug reports from the last year or so from the archives.

There's apparently a lack of understanding of what exactly are these types
are supposed to do. Therefore, instead of addressing each bug
individually, let me first state what I reconstructed as the specification
of these types, and then add what is currently wrong with it.


The cidr type stores the identity of an IP _network_. A network
specification is of the form 'x.x.x.x/y'. The documentation states that if
y is omitted then it is constructed from the old A, B, C class scheme. So
be it. In a real world network, the bits (y+1)...32 have to be zero, but
the cidr type does not currently enforce this. This has been the source of
bugs in the past, and no doubt the source of some confusion as well. I
propose that cidr _reject_ input of the form ''. If you think
about it, this is the same as int4 rejecting 3.5 as input.


The inet type stores the identity of an IP _host_. A host specification is
of the form 'x.x.x.x'. Optionally, the inet type also stores the identity
of the network the host is in. E.g., '' means the host in the network 127.0/16.

* Type equivalency

This has also been a source of problems. I propose that cidr and inet are
not made equivalent types at any level. No automatic casting either. A
network and a host are not the same thing. To construct a cidr value from
an inet value, you'd have to use some sort of (to be created) network()
function, e.g., network('') => '127.0/16'. IMO, there is no
reasonable way to construct an inet value from a cidr value.

* Operators

Because the types are equivalent, the operators have also been bunched
together in confusing ways. I propose that ordering operators (>, +, <)
between inet and cidr be eliminated, they do not make sense. The only
useful operation between cidr and inet is the << ("contains") operator.
Ordering withing cidr and inet be defined in terms of their bit
representation, as is the case now. The << family of operators should also
be removed for the inet type -- a host cannot "contain" another host. What
you probably wanted is `inet1 << network(inet2)'.

Does anyone see this differently? If not, can we agree on this

Peter Eisentraut                  Sernanders väg 10:115
peter_e(at)gmx(dot)net                   75262 Uppsala            Sweden


pgsql-hackers by date

Next:From: Peter EisentrautDate: 2000-07-05 00:12:41
Subject: Re: Article on MySQL vs. Postgres
Previous:From: Peter EisentrautDate: 2000-07-05 00:12:24
Subject: Re: Changes to handling version numbers internally

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group