IP Version 4 Networks and Host Addresses

The cidr type stores networks specified in CIDR (Classless Inter-Domain Routing) notation. The inet type stores hosts and networks in CIDR notation using a simple variation in representation to represent simple host TCP/IP addresses.

Table 3-19. PostgresIP Version 4 Types

IPV4 TypeStorageDescriptionRange
cidrvariableCIDR networksValid IPV4 CIDR blocks
inetvariablenets and hostsValid IPV4 CIDR blocks

CIDR

The cidr type holds a CIDR network. 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.

Here are some examples:

Table 3-20. 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

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, 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 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 off the bits part.