Re: pg, mysql comparison with "group by" clause - Mailing list pgsql-sql

From Tom Lane
Subject Re: pg, mysql comparison with "group by" clause
Date
Msg-id 16344.1129168246@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg, mysql comparison with "group by" clause  (Greg Stark <gsstark@mit.edu>)
List pgsql-sql
Greg Stark <gsstark@mit.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


pgsql-sql by date:

Previous
From: Frank Bax
Date:
Subject: Re: SEVEN cross joins?!?!?
Next
From: "Stewart Ben (RBAU/EQS4) *"
Date:
Subject: Re: SEVEN cross joins?!?!?