pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedinvalid 'having' clause
3+ messages / 2 participants
[nested] [flat]
* invalid 'having' clause
@ 2004-12-02 02:22 Iain <iain@mst.co.jp>
0 siblings, 1 reply; 3+ messages in thread
From: Iain @ 2004-12-02 02:22 UTC (permalink / raw)
To: pgsql-sql
Hi,
Just a quick question out of curiosity, I was just wondering if this is
supposed to be valid sql:
select count(*) as cnt
from sometable
group by somecolumn
having cnt > 1
This isn't valid in pg (7.4.6), but this is:
select count(*)
from sometable
group by somecolumn
having count(*) > 1
Does anyone have any idea?
I can't remember what other databases do, and I'm not so familiar with the
standards, but I just thought I'd mention it anyway.
regards
Iain
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: invalid 'having' clause
@ 2004-12-02 02:54 Tom Lane <tgl@sss.pgh.pa.us>
parent: Iain <iain@mst.co.jp>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2004-12-02 02:54 UTC (permalink / raw)
To: Iain <iain@mst.co.jp>; +Cc: pgsql-sql
"Iain" <iain@mst.co.jp> writes:
> Just a quick question out of curiosity, I was just wondering if this is
> supposed to be valid sql:
> select count(*) as cnt
> from sometable
> group by somecolumn
> having cnt > 1
No. The HAVING clause logically executes before the SELECT output list
does, so it makes no sense for it to refer to the output list entries.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: invalid 'having' clause
@ 2004-12-02 07:46 Iain <iain@mst.co.jp>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Iain @ 2004-12-02 07:46 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
OK, thanks. That seems to make sense.
regards
Iain
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Iain" <iain@mst.co.jp>
Cc: <pgsql-sql@postgresql.org>
Sent: Thursday, December 02, 2004 11:54 AM
Subject: Re: [SQL] invalid 'having' clause
> "Iain" <iain@mst.co.jp> writes:
>> Just a quick question out of curiosity, I was just wondering if this is
>> supposed to be valid sql:
>
>> select count(*) as cnt
>> from sometable
>> group by somecolumn
>> having cnt > 1
>
> No. The HAVING clause logically executes before the SELECT output list
> does, so it makes no sense for it to refer to the output list entries.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-12-02 07:46 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-12-02 02:22 invalid 'having' clause Iain <iain@mst.co.jp>
2004-12-02 02:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-12-02 07:46 ` Iain <iain@mst.co.jp>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox