pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedFilter certain range of IP address.
8+ messages / 5 participants
[nested] [flat]
* Filter certain range of IP address.
@ 2017-04-07 14:13 Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
0 siblings, 1 reply; 8+ messages in thread
From: Dinesh Chandra 12108 @ 2017-04-07 14:13 UTC (permalink / raw)
To: pgsql-performance-owner@postgresql.org <pgsql-performance-owner@postgresql.org>; +Cc: pgsql-performance
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<mailto:%7Cdinesh.chandra@cyient.com>
Plot No. 7, NSEZ, Phase-II ,Noida-Dadri Road, Noida - 201 305,India.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Filter certain range of IP address.
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
@ 2017-04-07 14:22 ` vinny <vinny@xs4all.nl>
2017-04-07 15:18 ` Re: Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
0 siblings, 1 reply; 8+ messages in thread
From: vinny @ 2017-04-07 14:22 UTC (permalink / raw)
To: Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>; +Cc: pgsql-performance-owner@postgresql.org; 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.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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Filter certain range of IP address.
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
@ 2017-04-07 15:18 ` Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 15:29 ` Re: Filter certain range of IP address. David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Dinesh Chandra 12108 @ 2017-04-07 15:18 UTC (permalink / raw)
To: vinny <vinny@xs4all.nl>; +Cc: pgsql-performance-owner@postgresql.org <pgsql-performance-owner@postgresql.org>; pgsql-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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Filter certain range of IP address.
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
2017-04-07 15:18 ` Re: Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
@ 2017-04-07 15:29 ` David G. Johnston <david.g.johnston@gmail.com>
2017-04-07 15:56 ` Re: Filter certain range of IP address. Rick Otten <rottenwindfish@gmail.com>
2017-04-10 11:33 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
0 siblings, 2 replies; 8+ messages in thread
From: David G. Johnston @ 2017-04-07 15:29 UTC (permalink / raw)
To: Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>; +Cc: vinny <vinny@xs4all.nl>; pgsql-performance-owner@postgresql.org <pgsql-performance-owner@postgresql.org>; pgsql-performance
On Fri, Apr 7, 2017 at 8:18 AM, Dinesh Chandra 12108 <
Dinesh.Chandra@cyient.com> wrote:
> 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
>
SELECT ... WHERE substring(ip_addr::text, 1, 10) = '172.23.110'
David J.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Filter certain range of IP address.
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
2017-04-07 15:18 ` Re: Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 15:29 ` Re: Filter certain range of IP address. David G. Johnston <david.g.johnston@gmail.com>
@ 2017-04-07 15:56 ` Rick Otten <rottenwindfish@gmail.com>
2017-04-07 16:09 ` Re: Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 16:20 ` Re: Filter certain range of IP address. Moreno Andreo <moreno.andreo@evolu-s.it>
1 sibling, 2 replies; 8+ messages in thread
From: Rick Otten @ 2017-04-07 15:56 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>; vinny <vinny@xs4all.nl>; pgsql-performance-owner@postgresql.org <pgsql-performance-owner@postgresql.org>; pgsql-performance
On Fri, Apr 7, 2017 at 11:29 AM, David G. Johnston <
david.g.johnston@gmail.com> wrote:
> On Fri, Apr 7, 2017 at 8:18 AM, Dinesh Chandra 12108 <
> Dinesh.Chandra@cyient.com> wrote:
>
>> 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
>>
>
> SELECT ... WHERE substring(ip_addr::text, 1, 10) = '172.23.110'
>
or
select ... where ip_addr << '172.23.110/32';
if ip_addr is an inet data type -- https://www.postgresql.org/
docs/9.6/static/functions-net.html
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Filter certain range of IP address.
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
2017-04-07 15:18 ` Re: Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 15:29 ` Re: Filter certain range of IP address. David G. Johnston <david.g.johnston@gmail.com>
2017-04-07 15:56 ` Re: Filter certain range of IP address. Rick Otten <rottenwindfish@gmail.com>
@ 2017-04-07 16:09 ` Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
1 sibling, 0 replies; 8+ messages in thread
From: Dinesh Chandra 12108 @ 2017-04-07 16:09 UTC (permalink / raw)
To: Rick Otten <rottenwindfish@gmail.com>; David G. Johnston <david.g.johnston@gmail.com>; +Cc: vinny <vinny@xs4all.nl>; pgsql-performance-owner@postgresql.org <pgsql-performance-owner@postgresql.org>; pgsql-performance
Thanks.
It’s working fine.
Thank you so much
Regards,
Dinesh Chandra
|Database administrator (Oracle/PostgreSQL)| Cyient Ltd. Noida.
------------------------------------------------------------------
Mobile: +91-9953975849 | Ext 1078 |dinesh.chandra@cyient.com<mailto:%7Cdinesh.chandra@cyient.com>
Plot No. 7, NSEZ, Phase-II ,Noida-Dadri Road, Noida - 201 305,India.
From: Rick Otten [mailto:rottenwindfish@gmail.com]
Sent: 07 April, 2017 9:26 PM
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>; vinny <vinny@xs4all.nl>; pgsql-performance-owner@postgresql.org; pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Filter certain range of IP address.
On Fri, Apr 7, 2017 at 11:29 AM, David G. Johnston <david.g.johnston@gmail.com<mailto:david.g.johnston@gmail.com>> wrote:
On Fri, Apr 7, 2017 at 8:18 AM, Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com<mailto:Dinesh.Chandra@cyient.com>> wrote:
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
SELECT ... WHERE substring(ip_addr::text, 1, 10) = '172.23.110'
or
select ... where ip_addr << '172.23.110/32';
if ip_addr is an inet data type -- https://www.postgresql.org/docs/9.6/static/functions-net.html
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Filter certain range of IP address.
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
2017-04-07 15:18 ` Re: Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 15:29 ` Re: Filter certain range of IP address. David G. Johnston <david.g.johnston@gmail.com>
2017-04-07 15:56 ` Re: Filter certain range of IP address. Rick Otten <rottenwindfish@gmail.com>
@ 2017-04-07 16:20 ` Moreno Andreo <moreno.andreo@evolu-s.it>
1 sibling, 0 replies; 8+ messages in thread
From: Moreno Andreo @ 2017-04-07 16:20 UTC (permalink / raw)
To: pgsql-performance
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Il 07/04/2017 17:56, Rick Otten ha
scritto:<br>
</div>
<blockquote
cite="mid:CAMAYy4K_SJPJgZ9trUmkJhjnyY7rac0JDCDzhdDYZbL0foW5Ag@mail.gmail.com"
type="cite">
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Apr 7, 2017 at 11:29 AM,
David G. Johnston <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:david.g.johnston@gmail.com" target="_blank">david.g.johnston@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:arial,helvetica,sans-serif"><span
style="font-family:arial,sans-serif">On Fri, Apr 7,
2017 at 8:18 AM, Dinesh Chandra 12108 </span><span
dir="ltr" style="font-family:arial,sans-serif"><<a
moz-do-not-send="true"
href="mailto:Dinesh.Chandra@cyient.com"
target="_blank">Dinesh.Chandra@cyient.com</a>></span><span
style="font-family:arial,sans-serif"> wrote:</span><br>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">Dear Vinny,<br>
<br>
Thanks for your valuable replay.<br>
<br>
but I need a select query, which select only that
record which starts from IP "172.23.110" only from
below table.<br>
<br>
xxx 172.23.110.175<br>
yyy 172.23.110.178<br>
zzz 172.23.110.177<br>
aaa 172.23.110.176<br>
bbb 172.23.111.180<br>
ccc 172.23.115.26<br>
</blockquote>
<div><br>
</div>
<div style="font-family:arial,helvetica,sans-serif">SELECT
... WHERE substring(ip_addr::text, 1, 10) =
'172.23.110'</div>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div style="font-size:12.8px">or</div>
<div style="font-size:12.8px"> select ... where ip_addr
<< '172.23.110/32';</div>
</div>
</div>
</div>
</blockquote>
/32 is for one address only (fourth byte, which we want to exclude),
so we need to use /24 (as for CIDR notation), that would be equal to
a 255.255.255.0 subnet mask.<br>
<br>
My 2 cents<br>
Moreno<br>
<p><br>
</p>
</body>
</html>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Filter certain range of IP address.
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` Re: Filter certain range of IP address. vinny <vinny@xs4all.nl>
2017-04-07 15:18 ` Re: Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 15:29 ` Re: Filter certain range of IP address. David G. Johnston <david.g.johnston@gmail.com>
@ 2017-04-10 11:33 ` vinny <vinny@xs4all.nl>
1 sibling, 0 replies; 8+ messages in thread
From: vinny @ 2017-04-10 11:33 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>; pgsql-performance
On 2017-04-07 17:29, David G. Johnston wrote:
> On Fri, Apr 7, 2017 at 8:18 AM, Dinesh Chandra 12108
> <Dinesh.Chandra@cyient.com> wrote:
>
>> 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
>
> SELECT ... WHERE substring(ip_addr::text, 1, 10) = '172.23.110'
>
> David J.
>
While it's certainly possible to do it with a substring(), I'd strongly
advise against it,
for several reasons, but the main one is that it does not take into
account what happens to the presentation of the IP address when cast to
a string. There might be some conditions that cause it to render as
'172.023.110' instead of '172.23.110' just like numbers can be rendered
as '1.234,56' or '1,234.56' depending on locale, and that would break
the functionality without throwing an error.
Generally speaking; if you find yourself using a substring() on a
datatype other than a string,
you should check if there isn't an operator that already can do what you
want to do. PostgreSQL has operators
to do all the basic things with the datatypes it supports, so you don't
have to re-invent the wheel. :-)
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2017-04-10 11:33 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-04-07 14:13 Filter certain range of IP address. Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 14:22 ` vinny <vinny@xs4all.nl>
2017-04-07 15:18 ` Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 15:29 ` David G. Johnston <david.g.johnston@gmail.com>
2017-04-07 15:56 ` Rick Otten <rottenwindfish@gmail.com>
2017-04-07 16:09 ` Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>
2017-04-07 16:20 ` Moreno Andreo <moreno.andreo@evolu-s.it>
2017-04-10 11:33 ` vinny <vinny@xs4all.nl>
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