Skip site navigation (1) Skip section navigation (2)

select count(*) from hits group by count;

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: select count(*) from hits group by count;
Date: 2000-01-29 09:39:42
Message-ID: Pine.GSO.3.96.SK.1000129123357.18405o-100000@ra (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Hi there,

I have a table hits:
discovery=> \d hits
Table    = hits
|              Field               |              Type                | Length|
| msg_id                           | int4 not null                    |     4 |
| count                            | int4 not null                    |     4 |
| first_access                     | datetime default now ( )         |     8 |
| last_access                      | datetime                         |     8 |
Index:    hits_pkey

and query:
discovery=> select count(*)  from hits group by count;                         
ERROR:  Aggregates not allowed in GROUP BY clause

There's easy workaround :
discovery=> select count(*) as qq  from hits group by count;
but I'm curious is this a valid query ?
Last snapshot also behave like 6.5.3

Another question:
discovery=> select count(*) as qqq,* from hits group by last_access;
produces error:
ERROR:  Illegal use of aggregates or non-group column in target list

Do I really need to have all fields in GROUP clause ?
Mysql seems allows this ?



Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su,
phone: +007(095)939-16-83, +007(095)939-23-83


pgsql-hackers by date

Next:From: Michael MeskesDate: 2000-01-29 09:42:17
Subject: Re: [HACKERS] Copyright
Previous:From: Michael MeskesDate: 2000-01-29 09:36:55
Subject: Re: [HACKERS] Copyright

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group