Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Praise should be given to the Forum managers or the Tipmasters - they are what make it work - give them extra recognition!!! They are timely (prompt - unlike ACTUAL support sites) and on the ball!!!..."

Geography

Where in the world do Tek-Tips members come from?

Help! I need a function to look up the geography for an IP address

adventurous1 (Programmer)
30 Apr 11 11:38
Hi all...

I need help in writing a FUNCTION that will take an IP address and look it up in another table and return its corresponding geography values.(

A function is needed as I have millions of records to lookup and brute force SQL does not perform well.)

source record:

IP Address    Date
155.44.33.91  4/1/2011

lookup table:

start_ip      end_ip            city     state  zip
155.44.33.1   155.93.22.200     lakeland tx     55495
197.65.39.8   198.33.95.12      plano    ca     85167

Can someone help me with an answer?  Thanks!
feherke (Programmer)
30 Apr 11 13:01
Hi

Just a simple query like this could not be optimized neither with a stored function :

CODE

select
*
from adventurous1_table
where '155.44.33.91' between start_ip and end_ip
So what should actually happen with the result of the lookup ?
 

Feherke.
http://free.rootshell.be/~feherke/

adventurous1 (Programmer)
30 Apr 11 15:19
Result would be the original ip address and the extended attributes of the ip address, i.e. city, state, zip.
feherke (Programmer)
1 May 11 6:04
Hi

That is not a reason to use stored function. There is nothing a function can do and a regular query can not.
 

Feherke.
http://free.rootshell.be/~feherke/

feherke (Programmer)
1 May 11 10:18
Hi

Quote (adventurous1):

A function is needed as I have millions of records to lookup and brute force SQL does not perform well.
From another point of view : if your current query is slow, post it so we can analyze it. Also post the exact table structure including constraints and indexes.
 

Feherke.
http://free.rootshell.be/~feherke/

adventurous1 (Programmer)
1 May 11 11:52
A function will be more efficient going through a collection of records.  The query basically is a join on ip address to retrieve extended attributes per above.

select a.ip_address, b.city, b.state, b.zip
from ip_address
where a.ip_address is between b.start_ip and end_ip

There has to be a better way of doing this, as the performance over millions of records is horrible.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close