Postgres检查IP(inet)是否在IP范围列表中 [英] Postgres Check if IP (inet) is IN a list of IP Ranges

查看:198
本文介绍了Postgres检查IP(inet)是否在IP范围列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查某个IP是否在一定范围内,例如: SELECT * FROM ip_address WHERE ip IN(

I want to check if an IP exists in a range of ranges, eg: SELECT * FROM ip_address WHERE ip IN (<list of ip ranges>)

Postgresql文档声明使用<<操作员检查IP是否包含在单个IP范围内,例如: inet‘192.168.1.5’<< inet'192.168.1 / 24',但是我不确定如何在范围列表中使用它而不必构建<<的OR链。

Postgresql documentation states to use the << operator to check if an IP is contained within a single IP Range, eg: inet '192.168.1.5' << inet '192.168.1/24', but I'm not sure how to use it on a list of ranges without having to construct an OR chain of <<'s.

推荐答案

select inet '192.168.1.5' << any (array['192.168.1/24', '10/8']::inet[]);
 ?column? 
----------
 t

http://www.postgresql.org/docs/current/static/functions- comparisons.html#AEN18486

这篇关于Postgres检查IP(inet)是否在IP范围列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆