Re: Subselect Question

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Cc: Alex P <alex(at)meerkatsoft(dot)com>
Subject: Re: Subselect Question
Date: 2004-11-02 09:05:38
Message-ID: 2410667175.20041102110538@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You can't use the alias name in the sort, case, where etc.. you have
to use the entire subselect.
So you would order by (select max(pop)...)
and you would also case the full thing as well.
A bit of a pain but Tom Lane explained it in a post a couple days ago
and said the system was optimized so it actually only ran the subquery
once.

Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax

________________________________________________________________________________

Hi,

when creating a query with a subselect

SELECT name, (SELECT max(pop) FROM cities WHERE cities.state = states.name) AS max_pop
FROM states;

then it is not possible to sort after max_pop or use max_pop in a function or a CASE.

am I dont anything wrong or is this meant to be the case?

Thanks
Alex

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2004-11-02 09:27:09 Re: Subselect Question
Previous Message Katsaros Kwn/nos 2004-11-02 09:05:34 Re: Split query