I have a table that contains two cidr arrays. One contains hosts ip addresses and the second one network addresses.

I need to write a function that would execute query like this:

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

So basically I need to search records which ip_addr equals to one from the first array or ip_addr is contained within one of the networks from the second array.

有帮助吗?

解决方案

If I understand you correctly, you're looking for 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')
       )
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top