diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index 8efb77c24da..f88a66ed803 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -58,6 +58,11 @@ several possibilities for formats, such as date and time types.
character(n)
fixed-length character string
+
+ cidr
+
+ IP version 4 network or host address
+
circle
@@ -78,6 +83,11 @@ several possibilities for formats, such as date and time types.
real, double precision
double-precision floating-point number
+
+ inet
+
+ IP version 4 network or host address
+
int2
smallint
@@ -163,6 +173,14 @@ several possibilities for formats, such as date and time types.
+
+
+
+The cidr and inet types are designed to handle any IP type
+but only ipv4 is handled in the current implementation.
+Everything here that talks about ipv4 will apply to ipv6 in a future release.
+
+
Postgres Function Constants
@@ -500,17 +518,21 @@ This is set at compile time and may change in a future release.
There are two fundamental kinds of date and time measurements:
- clock time and time interval.
-Both quantities have continuity and smoothness, as does time itself.
+ absolute clock times and relative time intervals.
+Both quantities should demonstrate continuity and smoothness, as does time itself.
Postgres supplies two primary user-oriented
date and time types,
-datetime and timespan, as well as
-the related SQL92 types date and time.
+datetime and timespan, as well as
+the related SQL92 types timestamp,
+interval,
+date and time.
-Other date and time types are available
-also, mostly
+In a future release, datetime and timespan are likely
+to merge with the SQL92 types timestamp,
+interval.
+Other date and time types are also available, mostly
for historical reasons.
@@ -579,6 +601,9 @@ for historical reasons.
+
+timestamp is currently implemented separately from
+datetime, although they share input and output routines.
@@ -652,13 +677,26 @@ for historical reasons.
Postgres endevours to be compatible with
SQL92 definitions for typical usage.
The SQL92 standard has an odd mix of date and
-time types and capabilities. For example, although the date type
+time types and capabilities. Two obvious problems are:
+
+
+
+
+Although the date type
does not have an associated time zone, the
-time type can. The default time zone is specified as a constant offset
-from GMT/UTC;
- however, time zones in the real world can have no meaning unless
-associated with a date as well
-as a time since the offset will vary through the year.
+time type can or does.
+
+
+
+The default time zone is specified as a constant integer offset
+from GMT/UTC.
+
+
+
+However, time zones in the real world can have no meaning unless
+associated with a date as well as a time
+since the offset may vary through the year with daylight savings
+time boundaries.
To address these difficulties, Postgres
@@ -1412,3 +1450,127 @@ Circles are output using the first syntax.
+
+IP Version 4 Networks and Host Addresses
+
+
+The cidr type stores networks specified
+in CIDR notation.
+The inet type stores hosts and networks in CIDR notation.
+
+
+
+
+PostgresIP Version 4 Type
+IPV4
+
+
+
+ IPV4 Type
+ Storage
+ Description
+ Range
+
+
+
+
+ cidr
+ variable
+ CIDR networks
+ Valid IPV4 CIDR blocks
+
+
+ inet
+ variable
+ nets and hosts
+ Valid IPV4 CIDR blocks
+
+
+
+
+
+
+
+inet for IP Networks
+
+
+The cidr type holds a CIDR network.
+The format for specifying 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 the "/y" part is left off, it is calculated using assumptions from
+the old class system except that it is extended to include at least
+all of the octets in the input.
+Here are some examples.
+
+
+
+
+
+
+
+
+ Input
+ Output
+
+
+
+ select '192.168.1'::cidr
+ 192.168.1/24
+
+
+ select '192.168'::cidr
+ 192.168.0/24
+
+
+ select '128.1'::cidr
+ 128.1/16
+
+
+ select '128':::cidr
+ 128.0/16
+
+
+ select '128.1.2'::cidr
+ 128.1.2/24
+
+
+ select '10.1.2'::cidr
+ 10.1.2/24
+
+
+ select '10.1'::cidr
+ 10.1/16
+
+
+ select '10'::cidr
+ 10/8
+
+
+
+
+
+
+
+inet for IP Networks
+
+
+The inet type is designed to hold, in one field, all of the information
+about a host including the CIDR style subnet that it is in.
+Note that if you want to store proper CIDR networks, see 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 function 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, it is treated as "/32."
+On output, the "/y" part is not printed if it is /32.
+This allows the type to be used as a straight host type by just leaving of
+the bits part.
+
+
+
\ No newline at end of file
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index d72170e2788..a1103964f8d 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -624,5 +624,64 @@ support functions.
+
+IP V4 Functions
+
+
+
+PostgresIP V4 Functions
+
+
+
+ Function
+ Returns
+ Description
+ Example
+
+
+
+
+ broadcast(cidr)
+ text
+ construct broadcast address as text
+ broadcast('192.168.1.5/24') ==> '192.168.1.255'
+
+
+ broadcast(inet)
+ text
+ construct broadcast address as text
+ broadcast('192.168.1.5/24') ==> '192.168.1.255'
+
+
+ host(inet)
+ text
+ extract host address as text
+ host('192.168.1.5/24') ==> '192.168.1.5'
+
+
+ masklen(cidr)
+ int4
+ calculate netmask length
+ masklen('192.168.1.5/24') ==> 24
+
+
+ masklen(inet)
+ int4
+ calculate netmask length
+ masklen('192.168.1.5/24') ==> 24
+
+
+ netmask(inet)
+ text
+ construct netmask as text
+ netmask('192.168.1.5/24') ==> '255.255.255.0'
+
+
+
+
+
+
+
+
diff --git a/doc/src/sgml/oper.sgml b/doc/src/sgml/oper.sgml
index 69834fb15e6..2c865ba9059 100644
--- a/doc/src/sgml/oper.sgml
+++ b/doc/src/sgml/oper.sgml
@@ -32,6 +32,25 @@ oprleft|oprright|oprresult|oprcode
+
+Users may invoke operators using the operator name, as in:
+
+
+select * from emp where salary < 40000;
+
+
+Alternatively, users may call the functions that implement the
+operators directly. In this case, the query above would be expressed
+as:
+
+select * from emp where int4lt(salary, 40000);
+
+
+
+psql
+has a command (\dd) to show these operators.
+
+
Lexical Precedence
@@ -633,23 +652,149 @@ are several operators for this type.
+
+IP V4 Operators
-Users may invoke operators using the operator name, as in:
+
+PostgresIP V4 Operators
+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
+
+
+ %gt;=
+ Greater or equal
+ '192.168.1.5'::cidr >= '192.168.1.5'::cidr
+
+
+ %gt;
+ Greater
+ '192.168.1.5'::cidr %gt; '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
+
+
+
+
+
+
-
-select * from emp where salary < 40000;
-
-
-Alternatively, users may call the functions that implement the
-operators directly. In this case, the query above would be expressed
-as:
-
-select * from emp where int4lt(salary, 40000);
-
+
+IP V4 Operators
-psql
-has a command (\dd) to show these operators.
+
+PostgresIP V4 Operators
+Operators
+
+
+
+ Operator
+ Description
+ Usage
+
+
+
+
+ <
+ Less than
+ '192.168.1.5'::inet < '192.168.1.6'::inet
+
+
+ <=
+ Less than or equal
+ '192.168.1.5'::inet <= '192.168.1.5'::inet
+
+
+ =
+ Equals
+ '192.168.1.5'::inet = '192.168.1.5'::inet
+
+
+ %gt;=
+ Greater or equal
+ '192.168.1.5'::inet >= '192.168.1.5'::inet
+
+
+ %gt;
+ Greater
+ '192.168.1.5'::inet %gt; '192.168.1.4'::inet
+
+
+ <>
+ Not equal
+ '192.168.1.5'::inet <> '192.168.1.4'::inet
+
+
+ <<
+ is contained within
+ '192.168.1.5'::inet << '192.168.1/24'::inet
+
+
+ <<=
+ is contained within or equals
+ '192.168.1/24'::inet <<= '192.168.1/24'::inet
+
+
+ >>
+ contains
+ '192.168.1/24'::inet >> '192.168.1.5'::inet
+
+
+ >>=
+ contains or equals
+ '192.168.1/24'::inet >>= '192.168.1/24'::inet
+
+
+
+
+
+
+