pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
column label
4+ messages / 3 participants
[nested] [flat]

* column label
@ 2003-03-21 20:55  Ryan <pgsql-sql@seahat.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Ryan @ 2003-03-21 20:55 UTC (permalink / raw)
  To: pgsql-sql

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)

Ryan





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: column label
@ 2003-03-24 09:33  Tomasz Myrta <jasiek@klaster.net>
  parent: Ryan <pgsql-sql@seahat.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tomasz Myrta @ 2003-03-24 09:33 UTC (permalink / raw)
  To: Ryan <pgsql-sql@seahat.com>; +Cc: 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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: column label
@ 2003-03-25 14:50  Ryan <pgsql-sql@seahat.com>
  parent: Tomasz Myrta <jasiek@klaster.net>
  0 siblings, 0 replies; 4+ messages in thread

From: Ryan @ 2003-03-25 14:50 UTC (permalink / raw)
  To: jasiek@klaster.net; +Cc: 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
Thats kind of a pain...  I'd rather perform the calculation once and then
do my order and where on the one value.  Is there any reason why postgres
does not recognize labels under WHERE?

The reason I use points is because my customized web-based image
mapping/ocr program can deal with points very aptly.  Also with a distance
based calc overlap is not really an issue as with polygons.  The reason I
am trying to limit the distance is simply to cut out clicking on far away
parts of the image.  Heck, I could check distance on the program side of
things but I try and keep as much in SQL as possible.

Ryan




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: column label
@ 2003-03-26 09:55  Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 0 replies; 4+ messages in thread

From: Christoph Haller @ 2003-03-26 09:55 UTC (permalink / raw)
  To: pgsql-sql; +Cc: pgsql-sql@seahat.com

> >> 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 =3D '2322' and
> >>   block_number =3D '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 =3D '2322' and
> >     block_number =3D '140'
> >    where '(10,10)'::point <-> point(x,y)<10
> >    order by '(10,10)'::point <-> point(x,y)
> >    limit 1;
> >
> Thats kind of a pain...  I'd rather perform the calculation once and
then
> do my order and where on the one value.  Is there any reason why
postgres
> does not recognize labels under WHERE?
>
So how about
select foo, distance from (
 select
  reference_number as foo,
  '(10,10)'::point <-> point(x,y) as distance
 from imagemap
  where
   index_number = '2322' and
   block_number = '140'
) as bar
where distance < 30
order by distance
limit 1;
The reason why postgres does not recognize labels under WHERE
is the WHERE clause is evaluated before column aliasing takes place.
But there is this valuable feature of using a sub-SELECT as
from_item, so this should not be a problem at all.
Alternatively you could use

 select
 reference_number,
 '(10,10)'::point <-> point(x,y)
from imagemap alias (foo, distance)
  where
   index_number = '2322' and
   block_number = '140' and distance < 30
  order by distance
  limit 1;

Does this help?

Regards, Christoph




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-03-26 09:55 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-03-21 20:55 column label Ryan <pgsql-sql@seahat.com>
2003-03-24 09:33 ` Tomasz Myrta <jasiek@klaster.net>
2003-03-25 14:50   ` Ryan <pgsql-sql@seahat.com>
2003-03-26 09:55 Re: column label Christoph Haller <ch@rodos.fzk.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox