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.

Table 8-14. PostgresIP Version 4 Types

IPV4 TypeStorageDescriptionRange
cidrvariableCIDR networksValid IPV4 CIDR blocks
inetvariablenets and hostsValid 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:

Table 8-15. PostgresIP Types Examples

CIDR InputCIDR Displayed
192.168.1192.168.1/24
192.168192.168.0/24
128.1128.1/16
128128.0/16
128.1.2128.1.2/24
10.1.210.1.2/24
10.110.1/16
1010/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.