Discussion:
Difference between inet and cidr
Yan Cheng CHEOK
2011-07-05 06:50:53 UTC
Permalink
May I know what is the difference among cidr and inet? I read through Network Address Type (http://www.postgresql.org/docs/8.3/static/datatype-net-types.html)
"""The essential difference between inet and cidr data types is that inet accepts values with nonzero bits to the right of the netmask, whereas cidr does not."""
I understand what is Subnet Mask from http://en.wikipedia.org/wiki/Subnetwork. But, what does it mean by "nonzero bits to the right of the netmask"? Is there any example to show the difference among the 2?
If I provide the following input 1.2.3.4, this is what I am getting if I view through pgAdmin.
inet = 1.2.3.4cidr = 1.2.3.4/32
Marti Raudsepp
2011-07-05 13:09:21 UTC
Permalink
Hi,
Post by Yan Cheng CHEOK
The essential difference between inet and cidr data types is that inet accepts values with nonzero bits to the right of the netmask, whereas cidr does not.
Say, if you have a /8 netmask, the 'cidr' type requires that all the
24 rightmost bits are zero. inet does not have this requirement.

E.g:
db=# select '255.0.0.0/8'::cidr;
255.0.0.0/8

db=# select '255.1.0.0/8'::cidr;
ERROR: invalid cidr value: "255.1.0.0/8"
DETAIL: Value has bits set to right of mask.

And inet allows this:
db=# select '255.1.0.0/8'::inet;
255.1.0.0/8

Hope that helps.

Regards,
Marti
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Harald Fuchs
2011-07-05 13:32:23 UTC
Permalink
Post by Marti Raudsepp
Hi,
Post by Yan Cheng CHEOK
The essential difference between inet and cidr data types is that inet accepts values with nonzero bits to the right of the netmask, whereas cidr does not.
Say, if you have a /8 netmask, the 'cidr' type requires that all the
24 rightmost bits are zero. inet does not have this requirement.
db=# select '255.0.0.0/8'::cidr;
255.0.0.0/8
db=# select '255.1.0.0/8'::cidr;
ERROR: invalid cidr value: "255.1.0.0/8"
DETAIL: Value has bits set to right of mask.
db=# select '255.1.0.0/8'::inet;
255.1.0.0/8
Hope that helps.
Do the inet/cidr types have any advantage over the ip4r contrib module?
--
Sent via pgsql-general mailing list (pgsql-general-RDL/***@public.gmane.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...