Re: HAVING <alias> ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: HAVING <alias> ...
Date: 2005-04-20 14:32:19
Message-ID: 25557.1114007539@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Marc G. Fournier" <scrappy(at)postgresql(dot)org> writes:
> Is there a reason (other then it hasn't been implemented yet?) that the
> following couldn't work?

> SELECT id,count(id) AS cnt
> FROM table
> WHERE id IN ( 1,2,3,4,5)
> GROUP BY id
> HAVING cnt = 2;

It's contrary to the SQL spec, for one thing ...

> SELECT id,count(id) AS cnt
> FROM table
> WHERE id IN ( 1,2,3,4,5)
> GROUP BY id
> HAVING count(id) = 2;

> The second one would have to 're-run' the COUNT against the table, would
> it not?

No, it doesn't. We've optimized out duplicate aggregate calls for
awhile now.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Held 2005-04-20 14:34:28 Re: argtype_inherit() is dead code
Previous Message Stephan Szabo 2005-04-20 14:26:18 Re: Foreign keys on array elements