X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BF65153CCC for ; Mon, 11 Apr 2005 05:51:33 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35938-03 for ; Mon, 11 Apr 2005 08:51:29 +0000 (GMT) Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id 7AD4453CE1 for ; Mon, 11 Apr 2005 05:51:27 -0300 (ADT) Received: (qmail 24314 invoked from network); 11 Apr 2005 10:51:30 +0200 Received: from unknown (HELO localhost) (boutiquenumerique-lists@192.168.0.4) by boutiquenumerique.com with SMTP; 11 Apr 2005 10:51:30 +0200 To: "Bill Lawrence" , pgsql-sql@postgresql.org Subject: Re: Getting the output of a function used in a where clause References: Message-ID: Date: Mon, 11 Apr 2005 10:51:28 +0200 From: PFC Organization: =?utf-8?Q?La_Boutique_Num=C3=A9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Opera M2(BETA2)/8.0 (Linux, build 987) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/150 X-Sequence-Number: 21043 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 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 > > >