From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | Giorgio Volpe <giorgio(dot)volpe(at)gtngroup(dot)it> |
Cc: | Postgresql <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: where cannot use alias name of column? |
Date: | 2001-09-13 13:58:15 |
Message-ID: | Pine.LNX.4.30.0109131553390.680-100000@peter.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Giorgio Volpe writes:
> May be it's my ignorance about sql ...
> but why cannot i use alias name of a column in a where clause?
>
> # select key as cc from mytable where cc > 0;
> ERROR: Attribute 'cc' not found
The processing order of this command is, perhaps unintuitively, FROM ->
WHERE -> SELECT [-> ORDER BY]. The aliases introduced in the SELECT list
are not available in the WHERE expression (but they would be in the ORDER
BY list). If you want to use an alias in the WHERE clause you have to
introduce it in the FROM clause, such as:
SELECT * FROM mytable AS myalias (xx, yy, zz) WHERE zz > 0;
This may or may not be actually useful in your case.
--
Peter Eisentraut peter_e(at)gmx(dot)net http://funkturm.homeip.net/~peter
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2001-09-13 14:02:31 | Re: count of occurences PLUS optimisation |
Previous Message | Fernando Schapachnik | 2001-09-13 12:09:28 | Re: where cannot use alias name of column? |