Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




9.11. Network Address Functions and Operators

Table 9-31 shows the operators available for the cidr and inet 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 part is identical to or a subnet of the other.

Table 9-31. cidr and inet Operators

Operator Description Example
< is less than inet '' < inet ''
<= is less than or equal inet '' <= inet ''
= equals inet '' = inet ''
>= is greater or equal inet '' >= inet ''
> is greater than inet '' > inet ''
<> is not equal inet '' <> inet ''
<< is contained within inet '' << inet '192.168.1/24'
<<= is contained within or equals inet '192.168.1/24' <<= inet '192.168.1/24'
>> contains inet '192.168.1/24' >> inet ''
>>= contains or equals inet '192.168.1/24' >>= inet '192.168.1/24'

Table 9-32 shows the functions available for use with the cidr and inet types. The host, text, and abbrev functions are primarily intended to offer alternative display formats. You can cast a text value to inet using normal casting syntax: inet( expression ) or colname ::inet.

Table 9-32. cidr and inet Functions

Function Return Type Description Example Result
broadcast(inet) inet broadcast address for network broadcast('')
host(inet) text extract IP address as text host('')
masklen(inet) int extract netmask length masklen('') 24
set_masklen(inet, int) inet set netmask length for inet value set_masklen('', 16)
netmask(inet) inet construct netmask for network netmask('')
hostmask(inet) inet construct host mask for network hostmask('')
network(inet) cidr extract network part of address network('')
text(inet) text extract IP address and netmask length as text text(inet '')
abbrev(inet) text abbreviated display format as text abbrev(cidr '') 10.1/16
family(inet) int extract family of address; 4 for IPv4, 6 for IPv6 family('::1') 6

Table 9-33 shows the functions available for use with the macaddr type. The function trunc(macaddr) returns a MAC address with the last 3 bytes set to zero. 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.

Table 9-33. macaddr Functions

Function Return Type Description Example Result
trunc(macaddr) macaddr set last 3 bytes to zero trunc(macaddr '12:34:56:78:90:ab') 12:34:56:00:00:00

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

  Published courtesy of The PostgreSQL Global Development Group Design by Interspire