Re: Filter certain range of IP address.

From: vinny <vinny(at)xs4all(dot)nl>
To: Dinesh Chandra 12108 <Dinesh(dot)Chandra(at)cyient(dot)com>
Cc: pgsql-performance-owner(at)postgresql(dot)org, pgsql-performance(at)postgresql(dot)org
Subject: Re: Filter certain range of IP address.
Date: 2017-04-07 14:22:20
Message-ID: 9deae42ab489b5856f600ea514bcd51a@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 2017-04-07 16:13, Dinesh Chandra 12108 wrote:
> Hi expert,
>
> May I know how to select a range of IP address.
>
> Example: I have number of different-2 IP's present in a table.
>
> I HAVE TO SELECT ONLY THAT IP ADDRESS WHICH DOES NOT START FROM PREFIX
> “172.23.110”.
>
> Thanks in advance
>
> REGARDS,
>
> DINESH CHANDRA
>
> |DATABASE ADMINISTRATOR (ORACLE/POSTGRESQL)| CYIENT LTD. NOIDA.
>
> ------------------------------------------------------------------
>
> Mobile: +91-9953975849 | Ext 1078 |dinesh(dot)chandra(at)cyient(dot)com
>
> Plot No. 7, NSEZ, Phase-II ,Noida-Dadri Road, Noida - 201 305,India.

If you store the ip address as the INET datatype then you can use the
INET operators
to see if any arbitraty number of bits match, the first 3 bytes means
the first 24 bits:

SELECT '172.23.110.55'::inet << '172.23.110.1/24'::inet;
?column?
----------
t
(1 row)

SELECT '272.23.110.55'::inet << '172.23.110.1/24'::inet;
?column?
----------
f
(1 row)

See also: https://www.postgresql.org/docs/9.3/static/functions-net.html

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Haider Ali 2017-04-07 14:56:53 Understanding PostgreSQL query execution time
Previous Message Dinesh Chandra 12108 2017-04-07 14:13:58 Filter certain range of IP address.