Re: Alias in the HAVING clause

Поиск
Список
Период
Сортировка
От Nathan Thatcher
Тема Re: Alias in the HAVING clause
Дата
Msg-id d9c17fb40805131456v596ec1d5n2918508b096aba45@mail.gmail.com
обсуждение исходный текст
Ответ на Alias in the HAVING clause  ("Nathan Thatcher" <n8thatcher@gmail.com>)
Список pgsql-general
Oops, that second query should be
SELECT COUNT(*), id % 3 AS f1 FROM table GROUP BY f1 HAVING id % 3 <> 0;


On Tue, May 13, 2008 at 3:43 PM, Nathan Thatcher <n8thatcher@gmail.com> wrote:
> I am in the middle of switching a bunch of queries over from MySQL to
>  PostgreSQL and have hit a little snag. The following query works fine
>  in MySQL but raises an error in postgres:
>
>  SELECT COUNT(*), id % 3 AS f1 FROM table GROUP BY f1 HAVING f1 <> 0;
>
>  It seems that Postgres does not recognize the alias in the HAVING
>  clause. Rewriting it like this works in postgres:
>
>  SELECT COUNT(*), id % 3 AS f1 FROM table GROUP BY f1 HAVING event_id % 3 <> 0;
>
>  I am wondering if I am missing something because this looks like my
>  expression (id % 3) is getting evaluated twice when it really only
>  should be done once. Now, this query is obviously watered down from
>  what I am really doing and the expression is fairly lengthy and
>  complex so I would prefer to not have to evaluate it more times than
>  necessary.
>
>  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?
>
>  Thanks,
>  Nate
>

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

Предыдущее
От: "Nathan Thatcher"
Дата:
Сообщение: Alias in the HAVING clause
Следующее
От: "Scott Marlowe"
Дата:
Сообщение: Re: Alias in the HAVING clause