11

我想检查一个 IP 是否存在于某个范围内,例如: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 链的。

4

1 回答 1

15
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

于 2014-07-24T21:21:28.373 回答