Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Alias in the HA...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 15534 of 17437
Post > Topic >>

Alias in the HAVING clause

by n8thatcher@[EMAIL PROTECTED] ("Nathan Thatcher") May 13, 2008 at 03:43 PM

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

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 6 Posts in Topic:
Alias in the HAVING clause
n8thatcher@[EMAIL PROTECT  2008-05-13 15:43:57 
Re: Alias in the HAVING clause
n8thatcher@[EMAIL PROTECT  2008-05-13 15:56:04 
Re: Alias in the HAVING clause
scott.marlowe@[EMAIL PROT  2008-05-13 16:18:23 
Re: Alias in the HAVING clause
tgl@[EMAIL PROTECTED] (T  2008-05-13 18:43:25 
Re: Alias in the HAVING clause
scott.marlowe@[EMAIL PROT  2008-05-13 16:22:03 
Re: Alias in the HAVING clause
n8thatcher@[EMAIL PROTECT  2008-05-13 17:33:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 12:59:06 CST 2008.