Network Address Functions and Operators

cidr and inet Operators

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.

cidr and inet Functions

The abbrev, host, and text functions are primarily intended to offer alternative display formats.

Any cidr value can be cast to inet implicitly or explicitly; therefore, the functions shown above as operating on inet also work on cidr values. An inet value can be cast to cidr. After the conversion, any bits to the right of the subnet mask are silently zeroed to create a valid cidr value. In addition, you can cast a text string to inet or cidr using normal casting syntax. For example, inet(expression) or colname::cidr.

macaddr Functions

The function trunc(macaddr) returns a MAC address with the last 3 bytes set to zero.

trunc(macaddr)

Description: Sets last 3 bytes to zero.

Return type: macaddr

For example:

1
2
3
4
5
SELECT trunc(macaddr '12:34:56:78:90:ab') AS RESULT;
      result       
-------------------
 12:34:56:00:00:00
(1 row)

The macaddr type also supports the standard relational operators (such as > and <=) for lexicographical ordering, and the bitwise arithmetic operators (~, & and |) for NOT, AND and OR.