Skip to content

HOSTMASK

Construct a host mask for an IPV4 or IPV6 network.

HOSTMASK(address, integer)
HOSTMASK(address, integer)

where address is an IPV4 or IPV6 address or expression, and integer is the subnet mask. The integer values must be in the range of 0 to 32 for IPV4 and 0 to 128 for IPV6.

To specify a constant value for the address argument, use the IPV4 or IPV6 keyword.

For example:

premdb=# select hostip, hostmask(hostip,24) from myhosts;
   hostip    | hostmask 
-------------+----------
 10.10.10.5  | 0.0.0.5
 10.10.10.6  | 0.0.0.6
 10.10.10.10 | 0.0.0.10
 10.10.190.1 | 0.0.0.1
(4 rows)

premdb=# select hostip, ipv4_hostmask(hostip,32) from myhosts;
   hostip    | ipv4_hostmask 
-------------+---------------
 10.10.10.5  | 0.0.0.0
 10.10.10.6  | 0.0.0.0
 10.10.10.10 | 0.0.0.0
 10.10.190.1 | 0.0.0.0
(4 rows)
premdb=# select hostmask(ipv6 '2001:0db8:85a3:0000:0000:8a2e:0370:7334',24) from sys.const;
               hostmask                 
-----------------------------------------
 0000:00b8:85a3:0000:0000:8a2e:0370:7334
(1 row)