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

Improving GROUP BY?

From: Oliver Siegmar <oliver(at)siegmar(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Improving GROUP BY?
Date: 2005-09-30 07:03:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general

as you all may know, the GROUP BY clause in PostgreSQL has to be parameterized 
with all fields that appear in the SELECT clause (except aggregates).


SELECT   id, foo, sum(bar)
FROM     table1
GROUP BY id, foo;

is perfectly valid, where

SELECT   id, foo, sum(bar)
FROM     table1

would fail with something like '"foo" must appear in the GROUP BY clause or be 
used in an aggregate function'.

I understand that behaviour in the case that the 'id' field wouldn't be a 
primary (or unique) identifier of the table.

So my questions are

- Would it be possible to add a feature to PostgreSQL to allow grouping by 
unique identifiers only?
- Is this requirement (all fields in GROUP BY) based on the SQL standard? If 
yes, by which version?




pgsql-general by date

Next:From: Richard HuxtonDate: 2005-09-30 07:04:36
Subject: Re: Many-To-Many Bridge Table Index
Previous:From: Peter EisentrautDate: 2005-09-30 06:56:46
Subject: Re: postmaster does not shut down

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