Getting the output of a function used in a where clause

From: "Bill Lawrence" <bill(dot)lawrence(at)cox(dot)net>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Getting the output of a function used in a where clause
Date: 2005-04-09 01:43:39
Message-ID: NEBBJBFOALCOMIDOAMHCCELJDAAA.bill.lawrence@cox.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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:

$sql = “SELECT zipcode from zipcodes where zipdist($lat1d,$lon1d,lat,long)
<= $dist;”;

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message John DeSoi 2005-04-09 15:00:20 Re: getting count for a specific querry
Previous Message PFC 2005-04-08 22:15:46 Re: getting count for a specific querry