pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedsearching cidr/inet arrays
2+ messages / 2 participants
[nested] [flat]
* searching cidr/inet arrays
@ 2005-04-25 18:46 Rob Casson <rob.casson@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Rob Casson @ 2005-04-25 18:46 UTC (permalink / raw)
To: pgsql-sql
i'm having trouble figuring out how to search in inet arrays....its
been a long time since i used postgres array support, so i may just be
bone-headed......
how can i determine if a given ip address is contained in the subnet
declaration inside an array?
{134.53.25.0/24,134.53.0.0/16}
{134.53.24.0/24}
i'd like to see which rows match an ip of, say, 134.53.24.2.....
thanks in advance, and sorry if this is a faq....i've googled
site:archives.postgresql.org, but haven't found my solution.....
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: searching cidr/inet arrays
@ 2005-04-25 20:24 Michael Fuhr <mike@fuhr.org>
parent: Rob Casson <rob.casson@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Fuhr @ 2005-04-25 20:24 UTC (permalink / raw)
To: Rob Casson <rob.casson@gmail.com>; +Cc: pgsql-sql
On Mon, Apr 25, 2005 at 02:46:37PM -0400, Rob Casson wrote:
>
> i'm having trouble figuring out how to search in inet arrays....its
> been a long time since i used postgres array support, so i may just be
> bone-headed......
>
> how can i determine if a given ip address is contained in the subnet
> declaration inside an array?
>
> {134.53.25.0/24,134.53.0.0/16}
> {134.53.24.0/24}
>
> i'd like to see which rows match an ip of, say, 134.53.24.2.....
See "Row and Array Comparisons" in the "Functions and Operators"
chapter of the documentation. The following works in 7.4 and later:
CREATE TABLE foo (
id serial PRIMARY KEY,
nets cidr[] NOT NULL
);
INSERT INTO foo (nets) VALUES ('{134.53.25.0/24,134.53.0.0/16}');
INSERT INTO foo (nets) VALUES ('{134.53.24.0/24}');
SELECT * FROM foo WHERE '134.53.24.2' << ANY (nets);
id | nets
----+--------------------------------
1 | {134.53.25.0/24,134.53.0.0/16}
2 | {134.53.24.0/24}
(2 rows)
SELECT * FROM foo WHERE '134.53.100.2' << ANY (nets);
id | nets
----+--------------------------------
1 | {134.53.25.0/24,134.53.0.0/16}
(1 row)
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-04-25 20:24 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-25 18:46 searching cidr/inet arrays Rob Casson <rob.casson@gmail.com>
2005-04-25 20:24 ` Michael Fuhr <mike@fuhr.org>
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