Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwUmT-0006wx-6E for pgsql-performance@arkaria.postgresql.org; Fri, 07 Apr 2017 14:22:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cwUmS-0005wY-HJ for pgsql-performance@arkaria.postgresql.org; Fri, 07 Apr 2017 14:22:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cwUmS-0005wB-2N for pgsql-performance@postgresql.org; Fri, 07 Apr 2017 14:22:28 +0000 Received: from lb3-smtp-cloud2.xs4all.net ([194.109.24.29]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cwUmO-0002RG-Nm for pgsql-performance@postgresql.org; Fri, 07 Apr 2017 14:22:26 +0000 Received: from webmail.xs4all.nl ([IPv6:2001:888:0:22:194:109:20:213]) by smtp-cloud2.xs4all.net with ESMTP id 5SNM1v0024R9iYA01SNM8M; Fri, 07 Apr 2017 16:22:21 +0200 Received: from mail.genj.nl ([77.242.116.162]) by webmail.xs4all.nl with HTTP (HTTP/1.1 POST); Fri, 07 Apr 2017 16:22:20 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 07 Apr 2017 16:22:20 +0200 From: vinny To: Dinesh Chandra 12108 Cc: pgsql-performance-owner@postgresql.org, pgsql-performance@postgresql.org Subject: Re: Filter certain range of IP address. In-Reply-To: References: Message-ID: <9deae42ab489b5856f600ea514bcd51a@xs4all.nl> X-Sender: vinny@xs4all.nl User-Agent: XS4ALL Webmail X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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