Re: JOINing based on whether an IP address is contained within a CIDR range?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jamie Tufnell" <diesql(at)googlemail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: JOINing based on whether an IP address is contained within a CIDR range?
Date: 2007-10-25 19:32:15
Message-ID: 23757.1193340735@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Jamie Tufnell" <diesql(at)googlemail(dot)com> writes:
> Is it possible to somehow JOIN using the <<= and
> = network operators?

Sure, why not?

You probably won't get a plan that's smarter than a nestloop, but I
imagine you'll have few enough rows in network_names that it won't
matter.

One potential problem is if there could be overlapping entries in
network_names --- the join would give you multiple rows for any
log entry that matches more than one network_names entry. You
could fix that using a subselect with LIMIT 1, as long as you
weren't too picky about which name got reported.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Fernando Hevia 2007-10-25 21:16:59 Re: request for help with COPY syntax
Previous Message Darnell Brawner 2007-10-25 19:32:00 hidden versioning system