9.12. Network Address Functions and Operators
Table 9.36 shows the operators available for thecidr andinet types. The operators<<,<<=,>>,>>=, and&& test for subnet inclusion. They consider only the network parts of the two addresses (ignoring any host part) and determine whether one network is identical to or a subnet of the other.
Table 9.36. cidr andinet Operators
| Operator | Description | Example |
|---|---|---|
< | is less than | inet '192.168.1.5' < inet '192.168.1.6' |
<= | is less than or equal | inet '192.168.1.5' <= inet '192.168.1.5' |
= | equals | inet '192.168.1.5' = inet '192.168.1.5' |
>= | is greater or equal | inet '192.168.1.5' >= inet '192.168.1.5' |
> | is greater than | inet '192.168.1.5' > inet '192.168.1.4' |
<> | is not equal | inet '192.168.1.5' <> inet '192.168.1.4' |
<< | is contained by | inet '192.168.1.5' << inet '192.168.1/24' |
<<= | is contained by or equals | inet '192.168.1/24' <<= inet '192.168.1/24' |
>> | contains | inet '192.168.1/24' >> inet '192.168.1.5' |
>>= | contains or equals | inet '192.168.1/24' >>= inet '192.168.1/24' |
&& | contains or is contained by | inet '192.168.1/24' && inet '192.168.1.80/28' |
~ | bitwise NOT | ~ inet '192.168.1.6' |
& | bitwise AND | inet '192.168.1.6' & inet '0.0.0.255' |
| | bitwise OR | inet '192.168.1.6' | inet '0.0.0.255' |
+ | addition | inet '192.168.1.6' + 25 |
- | subtraction | inet '192.168.1.43' - 36 |
- | subtraction | inet '192.168.1.43' - inet '192.168.1.19' |
Table 9.37 shows the functions available for use with thecidr andinet types. Theabbrev,host, andtext functions are primarily intended to offer alternative display formats.
Table 9.37. cidr andinet Functions
Anycidr value can be cast toinet implicitly or explicitly; therefore, the functions shown above as operating oninet also work oncidr values. (Where there are separate functions forinet andcidr, it is because the behavior should be different for the two cases.) Also, it is permitted to cast aninet value tocidr. When this is done, any bits to the right of the netmask are silently zeroed to create a validcidr value. In addition, you can cast a text value toinet orcidr using normal casting syntax: for example,inet( orexpression).colname::cidr
Table 9.38 shows the functions available for use with themacaddr type. The function returns a MAC address with the last 3 bytes set to zero. This can be used to associate the remaining prefix with a manufacturer.trunc(macaddr)
Table 9.38. macaddr Functions
Themacaddr type also supports the standard relational operators (>,<=, etc.) for lexicographical ordering, and the bitwise arithmetic operators (~,& and|) for NOT, AND and OR.
Table 9.39 shows the functions available for use with themacaddr8 type. The function returns a MAC address with the last 5 bytes set to zero. This can be used to associate the remaining prefix with a manufacturer.trunc(macaddr8)
Table 9.39. macaddr8 Functions
Themacaddr8 type also supports the standard relational operators (>,<=, etc.) for ordering, and the bitwise arithmetic operators (~,& and|) for NOT, AND and OR.