try:

SELECT zipcode, zipdist($lat1d,$lon1d,lat,long) as distance from zipcodes where distance <= $dist;â;

OR you could use a gist index with a geometric datatype to get it a lot faster.


On Sat, 09 Apr 2005 03:43:39 +0200, Bill Lawrence <[EMAIL PROTECTED]> wrote:


HI,

Iâm a newbie so please bear with me. I have a function defined (got it from
one of your threadsâ thanks Joe Conway) which calculates the distance
between 2 zip code centeroids (in lat,long). This thing works great.
However, I want to sort my results by distance without incurring the
additional burden of executing the function twice. A simplified version of
my current SQL (written in a perl cgi) that returns a set of zip codes
within a given radius is:



What I want to write is something like:

$sql = âSELECT zipcode, distance from zipcodes where distance <= $dist order
by distance;â;


But I donât the magic SQL phrase to populate the distance variable using my
nifty function. Do I need to create an output type for distance?


Thanks in advance!

Bill






---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to