Re: Datatype Inet and Searching

From: Guy Fraser <guy(at)incentre(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Datatype Inet and Searching
Date: 2003-12-03 18:32:47
Message-ID: 3FCE2C4F.4000102@incentre.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Devin Atencio wrote:

> Dear Users,
>
> I am very new to using the inet data type and I have a database with a
> list of CIDRs in it
>
> And I was hoping to be able to do some kind of select statement that
> would pull the record
>
> That the IP given is located in for example. If in my database I have
> a record like:
>
> Id cidr name
>
> 1 10.0.0.0/30 user1
>
> 2 10.0.0.4/30 user2
>
> 3 10.0.0.8/30 user3
>
> I was hoping to be able to do something like:
>
> Select * from mytable where cidr <<=’10.0.0.5’
>
> And the database would return only record 2 since it knows that
> 10.0.0.5 is contained only within record 2.
>
> I can’t seem to figure out the correct syntax to make this type of
> query happen. Any help would greatly
>
> Be appreciated.
>
> Devin Atencio
>
Select * from mytable where cidr >>= ’10.0.0.5’

or

Select * from mytable where ’10.0.0.5' <<= cidr

--
Guy Fraser
Network Administrator
The Internet Centre
780-450-6787 , 1-888-450-6787

There is a fine line between genius and lunacy, fear not, walk the
line with pride. Not all things will end up as you wanted, but you
will certainly discover things the meek and timid will miss out on.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Clint Stotesbery 2003-12-03 19:34:15 Help converting Oracle instead of triggers to PostgreSQL
Previous Message Gaetano Mendola 2003-12-03 18:02:34 Re: Datatype Inet and Searching