PostgreSQL, CIDR - search all ip addresses that are cotained within networks - from cidr array

StackOverflow https://stackoverflow.com/questions/23077853

문제

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