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