sql - PostgreSQL、CIDR - 从 cidr 数组中搜索网络中包含的所有 IP 地址

标签 sql arrays postgresql search cidr

我有一个包含两个 cidr 数组的表。第一个包含主机 IP 地址,第二个包含网络地址。

我需要编写一个函数来执行如下查询:

SELECT * from sometable 
WHERE ip_addr IN( 'all items from first array') OR
ip_addr << 'all item from second array'

所以基本上我需要搜索 ip_addr 等于第一个数组中的 1 的记录,或者 ip_addr 包含在第二个数组中的一个网络中。

最佳答案

如果我理解正确的话,您正在寻找the ANY comparison function

SELECT * 
  FROM sometable 
 WHERE (   ip_addr  = ANY ('all items from first array') 
        OR ip_addr << ANY ('all item from second array')
       )

关于sql - PostgreSQL、CIDR - 从 cidr 数组中搜索网络中包含的所有 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23077853/

相关文章:

SQL Server - 从多个客户端同时插入表 - 检查限制和阻止

objective-c - 将数组存储到 SQLite 数据库中

sql - 删除 jsonb 中的所有空字符串值 | Postgres

ruby-on-rails - 如何获得第一行的has_and_belongs_to_many关系postgresql

python - OpenErp - 外部 ID 批量更新

php - 为什么我从 MySQL 查询中得到重复项?

mysql - Linux 上的 MariaDB |访问 .sql 数据库

sql - 我怎样才能使用mysql查询删除表中的第n行

Ruby 在 Ruby 中创建 Hash 自定义反转函数

python - 从数组中选择元素