X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id CC11F9FB2E3 for ; Mon, 10 Jul 2006 21:24:40 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 20446-03 for ; Mon, 10 Jul 2006 21:24:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from outboundG.internet-mail-service.net (outboundG.internet-mail-service.net [216.240.47.207]) by postgresql.org (Postfix) with ESMTP id E9F899FB2D5 for ; Mon, 10 Jul 2006 21:24:36 -0300 (ADT) Received: from idiom.com (idiom.com [216.240.32.1]) by outbound.internet-mail-service.net (Postfix) with ESMTP id DCB413104DA for ; Mon, 10 Jul 2006 17:24:34 -0700 (PDT) Received: from [192.168.1.109] (adsl-71-135-172-180.dsl.pltn13.pacbell.net [71.135.172.180]) by idiom.com (8.12.11/8.12.11) with ESMTP id k6B0OXJt045264 for ; Mon, 10 Jul 2006 17:24:34 -0700 (PDT) (envelope-from bryce1@obviously.com) Message-ID: <44B2EFBC.1090201@obviously.com> Date: Mon, 10 Jul 2006 17:24:28 -0700 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060411 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Can function results be used in WHERE? References: <44B29376.2030107@obviously.com> <44B2CFC7.7060101@obviously.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/164 X-Sequence-Number: 25738 Aaron Bono wrote: > > > On 7/10/06, *Bryce Nesbitt* > wrote: > > > I think it is ugly also, but no other syntax seems to work: > > stage=# select > pod_code,lat,lon,calculate_distance(lat,lon,37.789629,-122.422082) as > dist from eg_pod where dist < 1 order by dist desc limit 10; > ERROR: column "dist" does not exist > > > SELECT > pod_code, > lat, > lon, > calculate_distance(lat,lon,37.789629,-122.422082) as dist > FROM eg_pod > WHERE calculate_distance(lat,lon, 37.789629,-122.422082) < 1 > ORDER BY calculate_distance(lat,lon,37.789629,-122.422082) desc limit 10; Yep, that works. I guess with IMMUTABLE it's even effecient. But I have to pass 6 arguments, not 2. Is there a way to make it look cleaner? I had expected using the column label (e.g. "dist") to work with WHERE, just as it does with ORDER BY. -Bryce -- ---- Visit http://www.obviously.com/