Re: Bounds checking on an alias

From: Alessio Bragadini <alessio(at)albourne(dot)com>
To: jkakar(at)expressus(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Bounds checking on an alias
Date: 2000-12-19 14:45:36
Message-ID: 3A3F7490.46EE0F0F@albourne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

jkakar(at)expressus(dot)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(at)albourne(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Emils Klotins 2000-12-19 16:10:39 group by: properly?
Previous Message Neil Thompson 2000-12-19 13:55:45 Re: Tree structure table normalization problem (do I need atrigger?)