Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
9.12. Network Address Functions and Operators
Prev UpChapter 9. Functions and OperatorsHome Next

9.12. Network Address Functions and Operators

Table 9.37 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.37. cidr andinet Operators

OperatorDescriptionExample
<is less thaninet '192.168.1.5' < inet '192.168.1.6'
<=is less than or equalinet '192.168.1.5' <= inet '192.168.1.5'
=equalsinet '192.168.1.5' = inet '192.168.1.5'
>=is greater or equalinet '192.168.1.5' >= inet '192.168.1.5'
>is greater thaninet '192.168.1.5' > inet '192.168.1.4'
<>is not equalinet '192.168.1.5' <> inet '192.168.1.4'
<<is contained byinet '192.168.1.5' << inet '192.168.1/24'
<<=is contained by 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'
&&contains or is contained byinet '192.168.1/24' && inet '192.168.1.80/28'
~bitwise NOT~ inet '192.168.1.6'
&bitwise ANDinet '192.168.1.6' & inet '0.0.0.255'
|bitwise ORinet '192.168.1.6' | inet '0.0.0.255'
+additioninet '192.168.1.6' + 25
-subtractioninet '192.168.1.43' - 36
-subtractioninet '192.168.1.43' - inet '192.168.1.19'

Table 9.38 shows the functions available for use with thecidr andinet types. Theabbrev,host, andtext functions are primarily intended to offer alternative display formats.

Table 9.38. cidr andinet Functions

FunctionReturn TypeDescriptionExampleResult
abbrev(inet)textabbreviated display format as textabbrev(inet '10.1.0.0/16')10.1.0.0/16
abbrev(cidr)textabbreviated display format as textabbrev(cidr '10.1.0.0/16')10.1/16
broadcast(inet)inetbroadcast address for networkbroadcast('192.168.1.5/24')192.168.1.255/24
family(inet)intextract family of address;4 for IPv4,6 for IPv6family('::1')6
host(inet)textextract IP address as texthost('192.168.1.5/24')192.168.1.5
hostmask(inet)inetconstruct host mask for networkhostmask('192.168.23.20/30')0.0.0.3
masklen(inet)intextract netmask lengthmasklen('192.168.1.5/24')24
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
set_masklen(inet,int)inetset netmask length forinet valueset_masklen('192.168.1.5/24', 16)192.168.1.5/16
set_masklen(cidr,int)cidrset netmask length forcidr valueset_masklen('192.168.1.0/24'::cidr, 16)192.168.0.0/16
text(inet)textextract IP address and netmask length as texttext(inet '192.168.1.5')192.168.1.5/32
inet_same_family(inet,inet)booleanare the addresses from the same family?inet_same_family('192.168.1.5/24', '::1')false
inet_merge(inet,inet)cidrthe smallest network which includes both of the given networksinet_merge('192.168.1.5/24', '192.168.2.5/24')192.168.0.0/22

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(expression) orcolname::cidr.

Table 9.39 shows the functions available for use with themacaddr type. The functiontrunc(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.

Table 9.39. macaddr Functions

FunctionReturn TypeDescriptionExampleResult
trunc(macaddr)macaddrset last 3 bytes to zerotrunc(macaddr '12:34:56:78:90:ab')12:34:56:00:00:00

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.40 shows the functions available for use with themacaddr8 type. The functiontrunc(macaddr8) returns a MAC address with the last 5 bytes set to zero. This can be used to associate the remaining prefix with a manufacturer.

Table 9.40. macaddr8 Functions

FunctionReturn TypeDescriptionExampleResult
trunc(macaddr8)macaddr8set last 5 bytes to zerotrunc(macaddr8 '12:34:56:78:90:ab:cd:ef')12:34:56:00:00:00:00:00
macaddr8_set7bit(macaddr8)macaddr8set 7th bit to one, also known as modified EUI-64, for inclusion in an IPv6 addressmacaddr8_set7bit(macaddr8 '00:34:56:ab:cd:ef')02:34:56:ff:fe:ab:cd:ef

Themacaddr8 type also supports the standard relational operators (>,<=, etc.) for ordering, and the bitwise arithmetic operators (~,& and|) for NOT, AND and OR.


Prev Up Next
9.11. Geometric Functions and Operators Home 9.13. Text Search Functions and Operators
epubpdf
Go to Postgres Pro Standard 12
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp