Re: IP adrss and networks in Postgresql

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: IP adrss and networks in Postgresql
Дата
Msg-id 14869.1076426496@sss.pgh.pa.us
обсуждение исходный текст
Ответ на IP adrss and networks in Postgresql  ("NTPT" <ntpt@centrum.cz>)
Список pgsql-general
"NTPT" <ntpt@centrum.cz> writes:
> I need to do some "IP address  based guessing" what should happen inside my application.Ie if given ip adress is from
network 'foo' do something, if given IP adrss is from network 'bar', do something else.  
> So  I need to set up table with network definitions like this :

> create table network_rules (network inet, rules text )

Most likely you want to declare the network column as 'cidr' not 'inet',
so that the datatype will enforce that it's a valid network spec.  I
can't imagine any case where you'd want bits set to the right of the
netmask in this table.

> Now i have given *some* ip adress and  I need  to create a  SELECT that return all networks with given ip adress
belongsto , ordered by netmask, most accurate (ie more bits in netmask set ) first. 

> Is it possible with postgres and inet datatype ?

Sure.  The contains-or-equals operator selects the rows you want
(network >>= 'target-ip') and you can order by masklen(network).

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: newbie pl/pgsql question on trigger function error
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: I want to use postresql for this app, but...