Question

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.

Was it helpful?

Solution

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')
       )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top