Re: match an IP address - Mailing list pgsql-general

From Scott Marlowe
Subject Re: match an IP address
Date
Msg-id dcc563d10809221021q908de44k29f17d07de214bde@mail.gmail.com
Whole thread Raw
In response to Re: match an IP address  (Joao Ferreira gmail <joao.miguel.c.ferreira@gmail.com>)
List pgsql-general
On Mon, Sep 22, 2008 at 11:16 AM, Joao Ferreira gmail
<joao.miguel.c.ferreira@gmail.com> wrote:
> well...
>
> my IP addresses are stored in a TEXT type field. that field can actually
> contain usernames like 'joao' or 'scott' and it can contain IP
> addresses....

Then cast them to inet and use the method I showed above:

postgres=# create table b as select a::text from inettest ;
SELECT
postgres=# select * from b;
       a
----------------
 192.168.0.1/32
 192.168.1.1/32
 10.0.0.1/32
(3 rows)

postgres=# select a from b where '192.168.0.1/0' >> a::inet;
       a
----------------
 192.168.0.1/32
 192.168.1.1/32
 10.0.0.1/32
(3 rows)

postgres=# select a from b where '192.168.0.1/24' >> a::inet;
       a
----------------
 192.168.0.1/32

pgsql-general by date:

Previous
From: Joao Ferreira gmail
Date:
Subject: Re: match an IP address
Next
From: Tino Wildenhain
Date:
Subject: Re: match an IP address