Postgresql - Functions and Operators 函数和运算 - Network Address

网络数据类型的函数和运算。使用的不会太多,但是功能比较全。

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'

~

~ inet '192.168.1.6'

&

inet '192.168.1.6' & inet '0.0.0.255'

|

inet '192.168.1.6' | inet '0.0.0.255'

+

inet '192.168.1.6' + 25

-

inet '192.168.1.43' - 36

-

计算区间内有多少IP

inet '192.168.1.43' - inet '192.168.1.19'

Function

Return Type

Description

Example

Result

abbrev(inet)

text

简写IP

abbrev(inet '10.1.0.0/16')

10.1.0.0/16

abbrev(cidr)

text

简写IP为cidr格式

abbrev(cidr '10.1.0.0/16')

10.1/16

broadcast(inet)

inet

取IP的广播地址

broadcast('192.168.1.5/24')

192.168.1.255/24

family(inet)

int

返回IP的类,4或6

family('::1')

6

host(inet)

text

IP值

host('192.168.1.5/24')

192.168.1.5

hostmask(inet)

inet

构造host mask

hostmask('192.168.23.20/30')

0.0.0.3

masklen(inet)

int

掩码值

masklen('192.168.1.5/24')

24

netmask(inet)

inet

获取掩码值

netmask('192.168.1.5/24')

255.255.255.0

network(inet)

cidr

提取IP段

network('192.168.1.5/24')

192.168.1.0/24

set_masklen(inet, int)

inet

更改掩码

set_masklen('192.168.1.5/24', 16)

192.168.1.5/16

set_masklen(cidr, int)

cidr

更改掩码

set_masklen('192.168.1.0/24'::cidr, 16)

192.168.0.0/16

text(inet)

text

设置IP格式为IP:掩码

text(inet '192.168.1.5')

192.168.1.5/32

inet_same_family(inet,inet)

boolean

IP地址是否是一个类(IP4或IP6)

inet_same_family('192.168.1.5/24', '::1')

false

inet_merge(inet, inet)

cidr

包含给定网络的最小网络

inet_merge('192.168.1.5/24', '192.168.2.5/24')

192.168.0.0/22

Function

Return Type

Description

Example

Result

trunc(macaddr)

macaddr

截取,设置后三位为00

trunc(macaddr '12:34:56:78:90:ab')

12:34:56:00:00:00

Function

Return Type

Description

Example

Result

trunc(macaddr8)

macaddr8

截取,设置后五位为00

trunc(macaddr8 '12:34:56:78:90:ab:cd:ef')

12:34:56:00:00:00:00:00

macaddr8_set7bit(macaddr8)

macaddr8

将二进制的第7位设置为1

macaddr8_set7bit(macaddr8 '00:34:56:ab:cd:ef')

02:34:56:ff:fe:ab:cd:ef

猜你喜欢

转载自blog.csdn.net/chuckchen1222/article/details/81386698