Re: pg, mysql comparison with "group by" clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>, Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, Rick Schumeyer <rschumeyer(at)ieee(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: pg, mysql comparison with "group by" clause
Date: 2005-10-13 01:50:46
Message-ID: 16344.1129168246@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Greg Stark <gsstark(at)mit(dot)edu> writes:
> I think most MySQL users don't stumble on it, they learn it as the way
> to handle the common use case when you join a master table against a
> detail table and then want to aggregate all the detail records. In
> standard SQL you have to write GROUP BY ... and list every single
> column you need from the master table. Forcing the database to do a
> lot of redundant comparisons and sort on uselessly long keys where in
> fact you only really need it to sort and group by the primary key.

Actually, if you're grouping by a table's primary key, the SQL99 spec
says you shouldn't have to explicitly list the other columns from that
table --- they are guaranteed to have unique values per group anyway.
This is a single case in the "functional dependency" stuff. That
verbiage is incredibly dense and I don't think we want to tackle all of
it any time soon, but the primary-key case probably wouldn't be very
hard to implement. We really ought to have this in TODO ... I'm sure
it's been discussed before.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stewart Ben (RBAU/EQS4) * 2005-10-13 02:02:42 Re: SEVEN cross joins?!?!?
Previous Message Frank Bax 2005-10-13 01:48:09 Re: SEVEN cross joins?!?!?