Re: Alias in the HAVING clause - Mailing list pgsql-general

From Nathan Thatcher
Subject Re: Alias in the HAVING clause
Date
Msg-id d9c17fb40805131633r7dd6656dt356d873fef8b9091@mail.gmail.com
Whole thread Raw
In response to Re: Alias in the HAVING clause  ("David Wilson" <david.t.wilson@gmail.com>)
List pgsql-general
Thank you all for the insight. PG is obviously my first choice (that
is why I am switching)... the hope is to do so without having to
change everything. Thanks for the solution David - it did the trick.

Nate

On Tue, May 13, 2008 at 5:01 PM, David Wilson <david.t.wilson@gmail.com> wrote:
> On Tue, May 13, 2008 at 5:43 PM, Nathan Thatcher <n8thatcher@gmail.com> 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Making sure \timing is on
Next
From: Alvaro Herrera
Date:
Subject: Re: Making sure \timing is on