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:13:37
Message-ID: dcc563d10809221013p6e854067n53eaf4150b61f07b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joao Ferreira gmail 2008-09-22 17:16:36 Re: match an IP address
Previous Message Raymond O'Donnell 2008-09-22 17:06:08 Re: match an IP address