Text Size: Normal / Large

6.10. Network Address Type Functions

Table 6-23 shows the operators available for the inet and cidr types. 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 6-23. cidr and inet Operators

OperatorDescriptionUsage
< Less thaninet '192.168.1.5' < inet '192.168.1.6'
<= Less than or equalinet '192.168.1.5' <= inet '192.168.1.5'
= Equalsinet '192.168.1.5' = inet '192.168.1.5'
>= Greater or equalinet '192.168.1.5' >= inet '192.168.1.5'
> Greaterinet '192.168.1.5' > inet '192.168.1.4'
<> Not equalinet '192.168.1.5' <> inet '192.168.1.4'
<< is contained withininet '192.168.1.5' << 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 '192.168.1.5'
>>= contains or equalsinet '192.168.1/24' >>= inet '192.168.1/24'

Table 6-24 shows the functions available for use with the inet and cidr types. 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 6-24. cidr and inet Functions

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

Table 6-25 shows the functions available for use with the mac type. 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.

Table 6-25. macaddr Functions

FunctionReturnsDescriptionExampleResult
trunc(macaddr)macaddrset last 3 bytes to zerotrunc(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.


User Comments

No comments could be found for this page.

Add Comment

Please use this form to add your own comments regarding your experience with particular features of PostgreSQL, clarifications of the documentation, or hints for other users. Please note, this is not a support forum, and your IP address will be logged. If you have a question or need help, please see the faq, try a mailing list, or join us on IRC. Note that submissions containing URLs or other keywords commonly found in 'spam' comments may be silently discarded. Please contact the webmaster if you think this is happening to you in error.

In order to submit a comment, you must have a community account.

* Comment
 

* denotes required field

Privacy Policy | Project hosted by hub.org | Designed by tinysofa
Copyright © 1996 – 2007 PostgreSQL Global Development Group