pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
To: vinny <vinny@xs4all.nl>
Cc: pgsql-performance-owner@postgresql.org <pgsql-performance-owner@postgresql.org>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Filter certain range of IP address.
Date: Fri, 7 Apr 2017 15:18:58 +0000
Message-ID: <705a033c9efe4a75830cc76b154e18a0@cyient.com> (raw)
In-Reply-To: <9deae42ab489b5856f600ea514bcd51a@xs4all.nl>
References: <cfb55df0df5547ccacef2b7390381bb3@cyient.com>
	<9deae42ab489b5856f600ea514bcd51a@xs4all.nl>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Dear Vinny,

Thanks for your valuable replay.

but I need a select query, which select only that record which starts from IP "172.23.110" only from below table.

xxx	172.23.110.175
yyy	172.23.110.178
zzz	172.23.110.177
aaa	172.23.110.176
bbb	172.23.111.180
ccc	172.23.115.26

Regards,
Dinesh Chandra
|Database administrator (Oracle/PostgreSQL)| Cyient Ltd. Noida.
------------------------------------------------------------------
Mobile: +91-9953975849 | Ext 1078 |dinesh.chandra@cyient.com 
Plot No. 7, NSEZ, Phase-II ,Noida-Dadri Road, Noida - 201 305,India.

-----Original Message-----
From: vinny [mailto:vinny@xs4all.nl] 
Sent: 07 April, 2017 7:52 PM
To: Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
Cc: pgsql-performance-owner@postgresql.org; pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Filter certain range of IP address.

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.chandra@cyient.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

-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance


view thread (8+ messages)  latest in thread

Message-ID: <705a033c9efe4a75830cc76b154e18a0@cyient.com>
Permalink:  ../705a033c9efe4a75830cc76b154e18a0@cyient.com/
Also on:    postgresql.org/message-id/705a033c9efe4a75830cc76b154e18a0@cyient.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: Dinesh.Chandra@cyient.com, vinny@xs4all.nl, pgsql-performance-owner@postgresql.org
  Subject: Re: Filter certain range of IP address.
  In-Reply-To: <705a033c9efe4a75830cc76b154e18a0@cyient.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox