INET_MERGE

Return the smallest network that includes both of the given IPV4 or IPV6 network IP addresses.

INET_MERGE(network1, integer1, network2, integer2)

where integer1 and integer2 are values for the subnet mask for each IP address. Integers must be in the range of 0 to 32 for IPV4 addresses and 0 to 128 for IPV6 addresses.

To specify a constant value for the network addresses, use the IPV4 or IPV6 keyword.

For example:
premdb=# select inet_merge(ipv4 '192.168.1.5', 24, ipv4 '192.168.2.5', 24) from sys.const;
   inet_merge   
----------------
 192.168.0.0/22
(1 row)
premdb=# select ipv6_inet_merge('2001:0db8:85a3:0000:0000:8a2e:0370:0000', 128, '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 128) from sys.const;
               ipv6_inet_merge               
---------------------------------------------
 2001:0db8:85a3:0000:0000:8a2e:0370:0000/113
(1 row)