Re: [GENERAL] Alias in the HAVING clause

2008-05-14 Thread Tom Lane
Robert Treat <[EMAIL PROTECTED]> writes: > ... but I have to wonder, if we have established f1 by the time > we evaluate the group by, shouldn't we also be able to determine f1 at having > time, and therefore allow alias in having in this instance? The key point is that we only allow output-li

Re: [GENERAL] Alias in the HAVING clause

2008-05-14 Thread Robert Treat
On Tuesday 13 May 2008 18:43:25 Tom Lane wrote: > "Scott Marlowe" <[EMAIL PROTECTED]> writes: > > On Tue, May 13, 2008 at 3:43 PM, Nathan Thatcher <[EMAIL PROTECTED]> wrote: > >> I am in the middle of switching a bunch of queries over from MySQL to > >> PostgreSQL and have hit a little snag. The f

Re: [GENERAL] Alias in the HAVING clause

2008-05-13 Thread Nathan Thatcher
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 <[EMAIL PROTECTED]> wrote: > On Tue, May 13

Re: [GENERAL] Alias in the HAVING clause

2008-05-13 Thread David Wilson
On Tue, May 13, 2008 at 5:43 PM, Nathan Thatcher <[EMAIL PROTECTED]> 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 a

Re: [GENERAL] Alias in the HAVING clause

2008-05-13 Thread Tom Lane
"Scott Marlowe" <[EMAIL PROTECTED]> writes: > On Tue, May 13, 2008 at 3:43 PM, Nathan Thatcher <[EMAIL PROTECTED]> 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

Re: [GENERAL] Alias in the HAVING clause

2008-05-13 Thread Scott Marlowe
On Tue, May 13, 2008 at 4:18 PM, Scott Marlowe <[EMAIL PROTECTED]> wrote: > On Tue, May 13, 2008 at 3:43 PM, Nathan Thatcher <[EMAIL PROTECTED]> 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 >

Re: [GENERAL] Alias in the HAVING clause

2008-05-13 Thread Scott Marlowe
On Tue, May 13, 2008 at 3:43 PM, Nathan Thatcher <[EMAIL PROTECTED]> 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 F

Re: [GENERAL] Alias in the HAVING clause

2008-05-13 Thread Nathan Thatcher
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 <[EMAIL PROTECTED]> wrote: > I am in the middle of switching a bunch of queries over from MySQL to > PostgreSQL and have hit a little snag.

[GENERAL] Alias in the HAVING clause

2008-05-13 Thread Nathan Thatcher
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