Re: column label

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Ryan <pgsql-sql(at)seahat(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: column label
Date: 2003-03-24 09:33:25
Message-ID: 3E7ED0E5.2060300@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Uz.ytkownik Ryan napisa?:
> Ok I have a query in a program that looks something like this
>
> select
> reference_number as foo,
> '(10,10)'::point <-> point(x,y) as distance
> from imagemap
> where
> index_number = '2322' and
> block_number = '140'
> order by distance
> limit 1;
>
> I wanted to add a clause in where 'and distance < 30'
> but according to the postgres manual it says I cannot do that for WHERE or
> HAVING clauses, instead use the real name.
>
> However dropping the 'as distance' from my query gives me a column name of
> '?column?' which happens to not be worth a dang thing.
>
> How can it be done?
>
> (I suddenly have a feeling its going to require a subselect)
Your feeling is 50% accurate. If you want to use subselect, throw "<10"
into this subselect, because you will have performance loss.

You can also use whole function in where clause and order by:
select
reference_number as foo,
'(10,10)'::point <-> point(x,y) as distance
from imagemap
where
index_number = '2322' and
block_number = '140'
where '(10,10)'::point <-> point(x,y)<10
order by '(10,10)'::point <-> point(x,y)
limit 1;

BTW Did you try to use polygons in your image maps, or you have rather
point oriented web page than area oriented?

Regards,
Tomasz Myrta

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2003-03-24 09:54:54 function with security definer
Previous Message Victor Yegorov 2003-03-24 08:20:14 Re: Seeking help with a query....