Re: Column alias in where clause?

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Column alias in where clause?
Дата
Msg-id 20080813171212.GC2958@svana.org
обсуждение исходный текст
Ответ на Column alias in where clause?  (Jeff Ross <jross@wykids.org>)
Ответы Re: Column alias in where clause?  (Jeff Ross <jross@wykids.org>)
Re: Column alias in where clause?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
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.

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.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Kevin Hunter
Дата:
Сообщение: Re: psql tutorial
Следующее
От: Kevin Hunter
Дата:
Сообщение: Re: automatic REINDEX-ing