Обсуждение: Determining if two subnets intersect

Поиск
Список
Период
Сортировка

Determining if two subnets intersect

От
Florian Weimer
Дата:
Is there some efficient PostgreSQL expression which is true if and
only if two subnets (given as values of type cidr) have non-empty
intersection (even if the intersection is not a CIDR network)?

-- 
Florian Weimer                       Florian.Weimer@RUS.Uni-Stuttgart.DE
University of Stuttgart           http://cert.uni-stuttgart.de/
RUS-CERT                          +49-711-685-5973/fax +49-711-685-5898


Re: Determining if two subnets intersect

От
Tom Lane
Дата:
Florian Weimer <Florian.Weimer@RUS.Uni-Stuttgart.DE> writes:
> Is there some efficient PostgreSQL expression which is true if and
> only if two subnets (given as values of type cidr) have non-empty
> intersection (even if the intersection is not a CIDR network)?

Maybe I'm missing something, but ISTM it's only possible for two
CIDR subnets to overlap if one contains the other.  So you could
check with
    A <<= B OR B <<= A
        regards, tom lane


Re: Determining if two subnets intersect

От
Florian Weimer
Дата:
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Florian Weimer <Florian.Weimer@RUS.Uni-Stuttgart.DE> writes:
> > Is there some efficient PostgreSQL expression which is true if and
> > only if two subnets (given as values of type cidr) have non-empty
> > intersection (even if the intersection is not a CIDR network)?
> 
> Maybe I'm missing something, but ISTM it's only possible for two
> CIDR subnets to overlap if one contains the other.  So you could
> check with
> 
>         A <<= B OR B <<= A

Oh, I think you are right; I haven't paid attention.  Thanks.

-- 
Florian Weimer                       Florian.Weimer@RUS.Uni-Stuttgart.DE
University of Stuttgart           http://cert.uni-stuttgart.de/
RUS-CERT                          +49-711-685-5973/fax +49-711-685-5898