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

From Joao Ferreira gmail
Subject Re: match an IP address
Date
Msg-id 1222103796.6786.59.camel@jmf-ubuntu
Whole thread Raw
In response to Re: match an IP address  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Responses Re: match an IP address
Re: match an IP address
List pgsql-general
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....



:(

joao


On Mon, 2008-09-22 at 11:13 -0600, Scott Marlowe wrote:
> On Mon, Sep 22, 2008 at 10:59 AM, Joao Ferreira gmail
> <joao.miguel.c.ferreira@gmail.com> wrote:
> > hello all,
> >
> > I'm unable to build a LIKE or SIMILAR TO expression for matching and ip
> > address
> >
> > 192.168.90.3
> > 10.3.2.1
>
> As already mentioned inet / cidr types should work.  Example:
>
> postgres=# create table inettest (a inet);
> CREATE TABLE
> postgres=# insert into inettest values
> ('192.168.0.1'),('192.168.1.1'),('10.0.0.1');
> INSERT 0 3
> postgres=# select a from inettest where '192.168.0.1/16' >> a;
>       a
> -------------
>  192.168.0.1
>  192.168.1.1
> (2 rows)
> postgres=# select a from inettest where '192.168.0.1/24' >> a;
>       a
> -------------
>  192.168.0.1
> (1 row)
> postgres=# select a from inettest where '192.168.0.1/0' >> a;
>       a
> -------------
>  192.168.0.1
>  192.168.1.1
>  10.0.0.1
> (3 rows)
>


pgsql-general by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: match an IP address
Next
From: "Scott Marlowe"
Date:
Subject: Re: match an IP address