From: | Jeff Ross <jross(at)wykids(dot)org> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Column alias in where clause? |
Date: | 2008-08-13 17:29:29 |
Message-ID: | 48A31A10.2070205@wykids.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Martijn van Oosterhout wrote:
> On Wed, Aug 13, 2008 at 10:47:17AM -0600, Jeff Ross wrote:
>> I'm a little confused about how to use a column alias in the where
>> clause of a query. I'm sure the answer is something simple, but I
>> haven't found anything searching through Google or from reading the docs.
>
> You can't. Conceptually, the result of the SELECT is not visible until
> *after* the WHERE clause has executed, so having the where clause
> depend on the select won't work.
>
Ah, now I get it!
> What you can do is put the CASE stuff in a subquery:
>
> SELECT * FROM
> (SELECT fc_facility_id, fc_name, CASE ...etc... )
> WHERE fc_director_name ilike ('%Cobb%');
>
> This way the inner select is done first, calculating the fields you
> want, then the outer select can use the result.
>
Perfect! Thank you!
Jeff
> Have a nice day,
>
>
> ------------------------------------------------------------------------
>
> !DSPAM:48a31748228425368819438!
From | Date | Subject | |
---|---|---|---|
Next Message | Bart Grantham | 2008-08-13 17:40:37 | Re: Alias for function return buffer in pl/pgsql? |
Previous Message | Kevin Hunter | 2008-08-13 17:16:03 | Re: automatic REINDEX-ing |