4
PostgreSQL에서는 아래와 같이 CIDR 범위의 상한 및 하한 경계를 얻을 수 있습니다.
그러나 두 IP 주소 (SQL에 의해)에서 CIDR을 가져올 수 있습니까?
예 :PostgreSQL의 두 IP에서 CIDR을 얻으려면 어떻게해야합니까?
입력 "192.168.0.0", "192.168.255.255"
출력은 "192.168.0.0/16는"
SELECT
network
,network::cidr
-- http://technobytz.com/ip-address-data-types-postgresql.html
--,netmask(network::cidr) AS nm
--,~netmask(network::cidr) AS nnm
,host(network::cidr) AS lower
,host(broadcast(network::cidr)) AS upper -- broadcast: last address in the range
,family(network::cidr) as fam -- IPv4, IPv6
,masklen(network::cidr) as masklen
FROM
(
SELECT CAST('192.168.1.1/32' AS varchar(100)) as network
UNION SELECT CAST('192.168.0.0/16' AS varchar(100)) as network
--UNION SELECT CAST('192.168.0.1/16' AS varchar(100)) as network
) AS tempT
['select inet_merge ('192.168.0.0', '192.168.255.255');'] (https://www.postgresql.org/docs/current/static/functions-net.html) – Abelisto