Re: match an IP address

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Joao Ferreira gmail" <joao(dot)miguel(dot)c(dot)ferreira(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: match an IP address
Date: 2008-09-22 17:21:48
Message-ID: dcc563d10809221021q908de44k29f17d07de214bde@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 22, 2008 at 11:16 AM, Joao Ferreira gmail
<joao(dot)miguel(dot)c(dot)ferreira(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tino Wildenhain 2008-09-22 21:34:50 Re: match an IP address
Previous Message Joao Ferreira gmail 2008-09-22 17:16:36 Re: match an IP address