Re: Getting the output of a function used in a where clause

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Bill Lawrence <bill(dot)lawrence(at)cox(dot)net>
Cc: PFC <lists(at)boutiquenumerique(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Getting the output of a function used in a where clause
Date: 2005-04-12 13:55:23
Message-ID: 1113314123.20921.117.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Why not just do:

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

On Mon, 2005-04-11 at 20:25, Bill Lawrence wrote:
> Boy I sure thought that would work... I received the following from postgres:
>
> ERROR: Attribute "distance" not found.
>
> Started looking into gist.... Looks complex.
>
> Any other ideas?
>
>
> -----Original Message-----
> From: PFC [mailto:lists(at)boutiquenumerique(dot)com]
> Sent: Monday, April 11, 2005 1:51 AM
> To: Bill Lawrence; pgsql-sql(at)postgresql(dot)org
> Subject: Re: [SQL] Getting the output of a function used in a where clause
>
>
> 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 <bill(dot)lawrence(at)cox(dot)net>
> 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 7: don't forget to increase your free space map settings

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Carlos Moreno 2005-04-12 14:55:30 Re: Update aborted if trigger function fails?
Previous Message Ilya A. Kovalenko 2005-04-12 12:34:04 operating "inet" type