Re: Alias in the HAVING clause

Поиск
Список
Период
Сортировка
Искать
От
David Wilson
Тема
Re: Alias in the HAVING clause
Дата
в 20:01:23
Msg-id
e7f9235d0805131601x25817293o75bcfde136d9b569@mail.gmail.com
Ответ на
Alias in the HAVING clause (Nathan Thatcher)
Список
Дерево обсуждения
Alias in the HAVING clause "Nathan Thatcher" <n8thatcher@gmail.com>
Re: Alias in the HAVING clause "Nathan Thatcher" <n8thatcher@gmail.com>
Re: Alias in the HAVING clause "Scott Marlowe" <scott.marlowe@gmail.com>
Re: Alias in the HAVING clause Tom Lane <tgl@sss.pgh.pa.us>
Re: Alias in the HAVING clause Robert Treat <xzilla@users.sourceforge.net>
Re: Alias in the HAVING clause Tom Lane <tgl@sss.pgh.pa.us>
Re: Alias in the HAVING clause "Scott Marlowe" <scott.marlowe@gmail.com>
Re: Alias in the HAVING clause "David Wilson" <david.t.wilson@gmail.com>
Re: Alias in the HAVING clause "Nathan Thatcher" <n8thatcher@gmail.com>
On Tue, May 13, 2008 at 5:43 PM, Nathan Thatcher  wrote:
> Is this the correct way to do this, or is there a better way / a way
> to get PostgreSQL to recognize an alias in the HAVING clause?

As Tom pointed out, f1's not in scope for the HAVING clause. If you're
that concerned about expression duplication, you could move the
calculation into a sub-select:

SELECT COUNT(*), f1 FROM (SELECT id % 3 AS f1 FROM table) t1 GROUP BY
f1 HAVING f1 <> 0;

-- 
- David T. Wilson
david.t.wilson@gmail.com
В списке pgsql-general по дате отправления
От: Tom Lane
Дата:
Сообщение: Re: Alias in the HAVING clause
От: Reece Hart
Дата:
FAQ