Полезная информация

4.10. Network Address Type Functions

Table 4-21. cidr and inet Operators

< Less thaninet '' < inet ''
<= Less than or equalinet '' <= inet ''
= Equalsinet '' = inet ''
>= Greater or equalinet '' >= inet ''
> Greaterinet '' > inet ''
<> Not equalinet '' <> inet ''
<< is contained withininet '' << inet '192.168.1/24'
<<= is contained within or equalsinet '192.168.1/24' <<= inet '192.168.1/24'
>> containsinet'192.168.1/24' >> inet ''
>>= contains or equalsinet '192.168.1/24' >>= inet '192.168.1/24'

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.

Table 4-22. cidr and inet Functions

broadcast(inet)inetbroadcast address for networkbroadcast('')
host(inet)textextract IP address as texthost('')
masklen(inet)integerextract netmask lengthmasklen('')24
set_masklen(inet,integer)inetset netmask length for inet valueset_masklen('',16)
netmask(inet)inetconstruct netmask for networknetmask('')
network(inet)cidrextract network part of addressnetwork('')
text(inet)textextract IP address and masklen as texttext(inet '')
abbrev(inet)textextract abbreviated display as textabbrev(cidr '')10.1/16

All of the functions for inet can be applied to cidr values as well. The host(), text(), and abbrev() functions are primarily intended to offer alternative display formats. You can cast a text field to inet using normal casting syntax: inet(expression) or colname::inet.

Table 4-23. macaddr Functions

trunc(macaddr)macaddrset last 3 bytes to zerotrunc(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 contrib/mac in the source distribution contains some utilities to create and maintain such an association table.

The macaddr type also supports the standard relational operators (>, <=, etc.) for lexicographical ordering.