7.19. IP Functions
- (ip_address, prefix_bits) → ipprefix
-
Returns the IP prefix of a given
ip_address
with subnet size ofprefix_bits
.ip_address
can be either of typeVARCHAR
or typeIPADDRESS
.
ip_subnet_min
(ip_prefix) → ip_address-
Returns the smallest IP address of type in the subnetspecified by
ip_prefix
.- SELECT ip_subnet_min(IPPREFIX '192.168.255.255/9'); — {192.128.0.0}
ip_subnet_max
(ip_prefix) → ip_address-
Returns the largest IP address of type
IPADDRESS
in the subnetspecified byip_prefix
.
ip_subnet_range
(ip_prefix) -> array(ip_address)-
Return an array of 2 IP addresses.The array contains the smallest and the largest IP addressin the subnet specified by
ip_prefix
.- SELECT ip_subnet_range(IPPREFIX '1.2.3.160/24'); — [{1.2.3.0}, {1.2.3.255}]
- (ip_prefix, ip_address) → boolean
-
Returns
true
if theip_address
is in the subnet ofip_prefix
.
is_subnet_of
(ip_prefix1, ip_prefix2) → boolean-
Returns
true
ifip_prefix2
is a subnet of .- SELECT is_subnet_of(IPPREFIX '192.168.3.131/26', IPPREFIX '192.168.3.144/30'); — true
- SELECT is_subnet_of(IPPREFIX '192.168.3.131/26', IPPREFIX '192.168.3.131/26'); — true