Re: field alias in where condition

From: Richard Huxton <dev(at)archonet(dot)com>
To: Havasvölgyi Ottó <h(dot)otto(at)freemail(dot)hu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: field alias in where condition
Date: 2005-06-03 14:53:55
Message-ID: 42A06F03.3080306@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Havasvölgyi Ottó wrote:
> Hi all,
>
> I issued the following queries:
>
>
> select substring(proname from 1 to 1) as nevresz, count(*)
> from pg_proc
> where nevresz = 'a'
> order by nevresz
> group by nevresz;
>
> select substring(proname from 1 to 1) as nevresz, count(*)
> from pg_proc
> order by nevresz
> group by nevresz;
>
> The first query fails, and says that column 'nevresz' does not exist.
> The second is OK.
>
> What is the problem? I cannot use column alias in where condition?

Correct. SQL defines it that way. You could reformulate as a sub-query
if you wanted:

SELECT nevresz,count(*)
FROM
(
SELECT substring(proname from 1 to 1) as nevresz FROM pg_proc
) AS dummy
GROUP BY nevresz
ORDER BY nevresz

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-06-03 15:11:18 Re: field alias in where condition
Previous Message Russ Brown 2005-06-03 14:53:51 Re: PG Lightning Admin running on Linux via WINE 2005524