From a2100230087b702e42d30a1e6a95e3192ffb16ff Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 10 Nov 2000 20:13:27 +0000 Subject: Adjust INET/CIDR display conventions and reimplement some INET/CIDR functions, per recent discussions on pghackers. For now, I have called the verbose-display formatting function text(), but will reconsider if enough people object. initdb forced. --- doc/src/sgml/datatype.sgml | 88 ++++++++++++++++++++++++++++----------------- doc/src/sgml/func.sgml | 74 ++++++++++++++++++++++++++++---------- doc/src/sgml/oper.sgml | 89 ++++++++-------------------------------------- 3 files changed, 125 insertions(+), 126 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index f3e7aa83abf..11ccc2a9a60 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,5 +1,5 @@ @@ -65,7 +65,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.38 2000/10/04 15:47:45 pe cidr - IP version 4 network or host address + IP network address circle @@ -95,7 +95,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.38 2000/10/04 15:47:45 pe inet - IP version 4 network or host address + IP network or host address int2 @@ -1736,7 +1736,7 @@ January 8 04:05:06 1999 PST Postgres offers data types to store IP and MAC - addresses. It is preferrable to use these types over plain text + addresses. It is preferable to use these types over plain text types, because these types offer input error checking and several specialized operators and functions. @@ -1755,16 +1755,16 @@ January 8 04:05:06 1999 PST cidr - 11 bytes + 12 bytes IP networks valid IPv4 networks inet - 11 bytes + 12 bytes IP hosts and networks - valid IPv4 hosts + valid IPv4 hosts or networks @@ -1784,19 +1784,48 @@ January 8 04:05:06 1999 PST + + <type>inet</type> + + + The inet type holds an IP host address, and + optionally the identity of the subnet it is in, all in one field. + The subnet identity is represented by the number of bits in the + network part of the address (the "netmask"). If the netmask is 32, + then the value does not indicate a subnet, only a single host. + Note that if you want to accept networks only, you should use the + cidr type rather than inet. + + + + The input format for this type is x.x.x.x/y where x.x.x.x is an IP address and + y is the number of + bits in the netmask. If the y part is left off, then the + netmask is 32, and the value represents just a single host. + On display, the /y + portion is suppressed if the netmask is 32. + + + <type>cidr</> - The cidr type holds an IP network. The format for + The cidr type holds an IP network specification. + Input and output formats follow Classless Internet Domain Routing + conventions. + The format for specifying classless networks is x.x.x.x/y where x.x.x.x is the network and y is the number of bits in the netmask. If y omitted, it is calculated - using assumptions from the older classfull naming system except - that it is extended to include at least all of the octets in the - input. + using assumptions from the older classful numbering system, except + that it will be at least large enough to include all of the octets + written in the input. @@ -1816,6 +1845,10 @@ January 8 04:05:06 1999 PST 192.168.100.128/25 192.168.100.128/25 + + 192.168/24 + 192.168.0/24 + 192.168/25 192.168.0.0/25 @@ -1856,30 +1889,19 @@ January 8 04:05:06 1999 PST - - - - <type>inet</type> - The inet type holds an IP host address, and - optionally the identity of the subnet it is in, all in one field. - Note that if you want to store networks only, you should use the - cidr type. The inet type is similar to - the cidr type except that the bits in the host part - can be non-zero. Functions exist to extract the various elements - of the field. - - - - The input format for this type is x.x.x.x/y where x.x.x.x is an internet host and - y is the number of - bits in the netmask. If the y part is left off, then the - netmask is 32 and you are effectively only storing the address of - a single host. + 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. + + + + If you do not like the output format for inet or + cidr values, try the host() and + text() functions. + + diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index c51e8905e10..655c63a7931 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1480,62 +1480,98 @@ Not defined by this name. Implements the intersection operator '#' <type>cidr</> and <type>inet</> Functions - + Function Returns Description Example + Result - - broadcast(cidr) - text - construct broadcast address as text - broadcast('192.168.1.5/24') - broadcast(inet) - text - construct broadcast address as text + inet + broadcast address for network broadcast('192.168.1.5/24') + 192.168.1.255/24 host(inet) text - extract host address as text + extract IP address as text host('192.168.1.5/24') - - - masklen(cidr) - integer - calculate netmask length - masklen('192.168.1.5/24') + 192.168.1.5 masklen(inet) integer - calculate netmask length + extract netmask length masklen('192.168.1.5/24') + 24 netmask(inet) - text - construct netmask as text + inet + construct netmask for network netmask('192.168.1.5/24') + 255.255.255.0 + + + network(inet) + cidr + extract network part of address + network('192.168.1.5/24') + 192.168.1/24 + + + text(inet) + text + extract IP address and masklen as text + text(inet '192.168.1.5') + 192.168.1.5/32 + + + +
+
+ + + All of the functions for inet can be applied to + cidr values as well. The host() and + text() functions are primarily intended to offer + alternative display formats. + + + + + <type>macaddr</> Functions + + + + Function + Returns + Description + Example + Result + + trunc(macaddr) macaddr set last 3 bytes to zero trunc(macaddr '12:34:56:78:90:ab') + 12:34:56:00:00:00
+
+ The function trunc(macaddr) returns a MAC address with the last 3 bytes set to 0. This can be used to associate the remaining prefix with a manufacturer. The directory diff --git a/doc/src/sgml/oper.sgml b/doc/src/sgml/oper.sgml index deb3d33cde8..8934323cd05 100644 --- a/doc/src/sgml/oper.sgml +++ b/doc/src/sgml/oper.sgml @@ -1,5 +1,5 @@ @@ -756,80 +756,11 @@ logical union Network Address Type Operators - - <type>cidr</> Operators + + <type>cidr</> and <type>inet</> Operators - - <type>cidr</> Operators - - - - Operator - Description - Usage - - - - - < - Less than - '192.168.1.5'::cidr < '192.168.1.6'::cidr - - - <= - Less than or equal - '192.168.1.5'::cidr <= '192.168.1.5'::cidr - - - = - Equals - '192.168.1.5'::cidr = '192.168.1.5'::cidr - - - >= - Greater or equal - '192.168.1.5'::cidr >= '192.168.1.5'::cidr - - - > - Greater - '192.168.1.5'::cidr > '192.168.1.4'::cidr - - - <> - Not equal - '192.168.1.5'::cidr <> '192.168.1.4'::cidr - - - << - is contained within - '192.168.1.5'::cidr << '192.168.1/24'::cidr - - - <<= - is contained within or equals - '192.168.1/24'::cidr <<= '192.168.1/24'::cidr - - - >> - contains - '192.168.1/24'::cidr >> '192.168.1.5'::cidr - - - >>= - contains or equals - '192.168.1/24'::cidr >>= '192.168.1/24'::cidr - - - -
-
- - - <type>inet</> Operators - - - <type>inet</> Operators +
+ <type>cidr</> and <type>inet</> Operators @@ -892,6 +823,16 @@ logical union
+ + + All of the operators for inet can be applied to + cidr values as well. The operators + << <<= + >> >>= + test for subnet inclusion: they consider only the network parts + of the two addresses, ignoring any host part, and determine whether + one network part is identical to or a subnet of the other. +
-- cgit v1.2.3