Received: from sapphire.albourne.com (sapphire.albourne.com [195.212.241.227]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eBJEjk686233 for ; Tue, 19 Dec 2000 09:45:46 -0500 (EST) (envelope-from alessio@albourne.com) Received: from albourne.com (akamas.albourne.com [195.212.241.254]) by sapphire.albourne.com (8.9.3/8.9.3/Albourne/CYS/1.9/MAPS) with ESMTP id QAA10811; Tue, 19 Dec 2000 16:45:37 +0200 (EET) Message-ID: <3A3F7490.46EE0F0F@albourne.com> Date: Tue, 19 Dec 2000 16:45:36 +0200 From: Alessio Bragadini Organization: APL Financial Services (Overseas) Ltd. X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.18pre21 i686) X-Accept-Language: it, en, sv MIME-Version: 1.0 To: jkakar@expressus.com CC: pgsql-sql@postgresql.org Subject: Re: Bounds checking on an alias References: <20001218171134.A4581@expressus.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200012/216 X-Sequence-Number: 550 jkakar@expressus.com wrote: > 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; > ERROR: Attribute 'distance' not found It's not related to your function or query, but it's a generic behaviour: changemaster=# select id + 1 as next, val from t; next | val ------+------ 2 | Test (1 row) changemaster=# select id + 1 as next, val from t where next > 1; ERROR: Attribute 'next' not found changemaster=# select id + 1 as next, val from t where id + 1 > 1; next | val ------+------ 2 | Test (1 row) The named expression isn't available in the WHERE clause. You have to copy the same expression in it. -- Alessio F. Bragadini alessio@albourne.com APL Financial Services http://village.albourne.com Nicosia, Cyprus phone: +357-2-755750 "It is more complicated than you think" -- The Eighth Networking Truth from RFC 1925