SELECT, GROUP BY, and aggregates

From: Ryan Delaney <ryan(dot)delaney(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: SELECT, GROUP BY, and aggregates
Date: 2015-02-13 05:04:49
Message-ID: 20150213050449.GQ5672@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Why couldn't an RDBMS such as postgres interpret a SELECT that omits the GROUP
BY as implicitly grouping by all the columns that aren't part of an aggregate?

If I do this, Postgres throws an exception that I cannot SELECT a series of
columns including an aggregate without a corresponding GROUP BY clause. But it
knew to throw the error, right? It must have some method of knowing which
columns aren't part of an aggregate. Or is it that a column might not have an
aggregate, but still be hard to figure out how to group by it?

But how would that happen?

If I omit something from GROUP BY, it throws another exception. If I put
something there that doesn't belong, I get a different exception. So it already
knows how to do this! :P
--
Regards,
Ryan Delaney
ryan(dot)delaney(at)gmail(dot)com
https://github.com/rpdelaney
GPG ID: 4096R/311C 10F2 26E0 14E3 8BA4 3B06 B634 36F1 C9E7 771B

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexey Bashtanov 2015-02-13 07:01:26 Re: How to hide stored procedure's bodies from specific user
Previous Message seb 2015-02-13 00:59:01 No repo for postgresql 9.4 for raspberry pi 2