Postgres CIDR。如何仅选择没有子网的网络?
我有一个表 Net,其中是网络列表
-- 表:net
CREATE TABLE net
(
id serial NOT NULL,
cidr cidr,
description text,
CONSTRAINT net_pkey PRIMARY KEY (id )
)
我需要选择所有不存在的网络。属于其他网络。即只有没有子网的网络。如何构建查询?
西德:
10.0.0.0/8
10.1.0.0/16
10.2.0.0/16
10.3.0.0/16
10.3.1.0/24
10.3.2.0/24
10.3.3.0/24
10.15.1.0/24
10.15.2.0/24
10.15.3.0/24
172.20.0.0/16
172.21.0.0/16
172.0.0.0/8
11.11.11.0/24
评分最高的网络为 10.0.0.0/8、172.0.0.0/8、11.11.11.0/24
I have a table Net where is the list of networks
-- Table: net
CREATE TABLE net
(
id serial NOT NULL,
cidr cidr,
description text,
CONSTRAINT net_pkey PRIMARY KEY (id )
)
I need to select all the networks that do not. belong to other networks. ie only network without subnets. How to build a query?
cidr:
10.0.0.0/8
10.1.0.0/16
10.2.0.0/16
10.3.0.0/16
10.3.1.0/24
10.3.2.0/24
10.3.3.0/24
10.15.1.0/24
10.15.2.0/24
10.15.3.0/24
172.20.0.0/16
172.21.0.0/16
172.0.0.0/8
11.11.11.0/24
Top rated net is 10.0.0.0/8, 172.0.0.0/8, 11.11.11.0/24
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是这样理解你的问题的:
您需要不包含在任何其他网络规范中的所有网络规范,即不属于另一个网络规范的一部分。
试试这个:
产生您预期的结果。
查看网络地址函数和运算符一章有关
>>
运算符的更多信息,请参阅手册。半连接
NOT EXISTS
可能是最快的方法。I understand your question like this:
You want all network specifications that are not contained in any other network specification, i.e. are not part of the subnet of another.
Try this:
Produces your expected result.
Have a look at the chapter Network Address Functions and Operators in the manual for more on the
>>
operator.Semi-join with
NOT EXISTS
is probably the fastest way to do this.