Received: from snigglefritz.expressus.com (dhcphost11.expressus.com [64.114.34.80]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eBJ1C7631509 for ; Mon, 18 Dec 2000 20:12:07 -0500 (EST) (envelope-from jkakar@expressus.com) Received: (from jkakar@localhost) by snigglefritz.expressus.com (8.11.1/8.11.1/Debian 8.11.0-6) id eBJ1CE004591 for pgsql-sql@postgresql.org; Mon, 18 Dec 2000 17:12:14 -0800 From: jkakar@expressus.com Date: Mon, 18 Dec 2000 17:11:34 -0800 To: pgsql-sql@postgresql.org Subject: Bounds checking on an alias Message-ID: <20001218171134.A4581@expressus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Archive-Number: 200012/204 X-Sequence-Number: 538 Hi, Removing the double single-quotes from the distance function fixed the problem, thanks. I've now encountered another problem... I have the following (ugly) query: SELECT DISTINCT tbl_restaurant.restaurant, tbl_restaurant_location.postal_code, tbl_restaurant_location.latitude AS latitude, tbl_restaurant_location.longitude AS longitude, distance (49.24894, -122.90419, latitude, longitude) AS distance FROM tbl_restaurant, tbl_restaurant_location, tbl_restaurant_cuisine_link WHERE tbl_restaurant.restaurant_id = tbl_restaurant_location.restaurant_id AND tbl_restaurant.restaurant_id = tbl_restaurant_cuisine_link.restaurant_id AND tbl_restaurant_cuisine_link.cuisine_id = 14 AND tbl_restaurant.price_id = 1 AND tbl_restaurant_location.latitude IS NOT NULL AND tbl_restaurant_location.latitude > 49.113804 AND tbl_restaurant_location.latitude < 49.384075 AND tbl_restaurant_location.longitude > -123.03932 AND tbl_restaurant_location.longitude < -122.76906 AND distance <= 15.0 ORDER BY distance; What I'm doing is selecting all restaurants of a particular cuisine and within a particular price range. Out of the restaurants that meet those criteria I only want the ones within a certain range of my location- in this case, 49.24894, -122.90419. The way I narrow down the search results is to select only those restaurants within certain lat/lon points; basically, I'm selecting restaurants that fall in a square region with my location in the middle. Then, I'm applying my distance formula to filter these results. When I try and do a "distance <= 15.0" I get: ERROR: Attribute 'distance' not found If I remove that particular clause it works fine but my results aren't as accurate as they need to be. Any ideas? Thanks, Jamu. -- Jamu Kakar (Developer) Expressus Design Studio, Inc. jkakar@expressus.com 708-1641 Lonsdale Avenue V: (604) 988-6999 North Vancouver, BC, V7M 2J5