Re: [PATCH] Allow star syntax in GROUP BY, as a shorthand for all table columns

Lists: pgsql-hackers
From: Marti Raudsepp <marti(at)juffo(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Allow star syntax in GROUP BY, as a shorthand for all table columns
Date: 2011-06-08 16:57:54
Message-ID: BANLkTinKs1dAUnB0Ct=OM3ncj0+PjjOkTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

This patch enables the syntax "GROUP BY tablename.*" in cases where
earlier you'd get the error "field must appear in the GROUP BY clause
or be used in an aggregate function"

I've often needed to write queries like this:
SELECT a.x, a.y, a.z, sum(b.w) FROM a JOIN b USING (a_id) GROUP BY
a.x, a.y, a.z;
Now this becomes:
SELECT a.x, a.y, a.z, sum(b.w) FROM a JOIN b USING (a_id) GROUP BY a.*;

The patch is so trivial that I'm wondering why it hasn't been
implemented before. I couldn't think of any assumptions being broken
by using row comparison instead of comparing each field separately.
But maybe I'm missing something.

If this patch looks reasonable, I guess the obvious next step is to
expand the "a.*" reference to the table's primary key columns and fill
in context->func_grouped_rels

Regards,
Marti

Attachment Content-Type Size
0001-Allow-star-syntax-in-GROUP-BY-as-a-shorthand-for-all.patch text/x-patch 3.3 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marti Raudsepp <marti(at)juffo(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Allow star syntax in GROUP BY, as a shorthand for all table columns
Date: 2011-06-08 17:22:15
Message-ID: 14953.1307553735@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Marti Raudsepp <marti(at)juffo(dot)org> writes:
> This patch enables the syntax "GROUP BY tablename.*" in cases where
> earlier you'd get the error "field must appear in the GROUP BY clause
> or be used in an aggregate function"

Is this really necessary now that we know about "GROUP BY primary key"?

> The patch is so trivial that I'm wondering why it hasn't been
> implemented before.

Probably because it's a nonstandard kluge ...

regards, tom lane


From: Marti Raudsepp <marti(at)juffo(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Allow star syntax in GROUP BY, as a shorthand for all table columns
Date: 2011-06-09 08:29:24
Message-ID: BANLkTimgqQc-_jyc3bsGLp+-XdpQsO-Dug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jun 8, 2011 at 20:22, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Is this really necessary now that we know about "GROUP BY primary key"?

You're right. I was just looking for something easy to hack on and
didn't put much thought into usefulness.
I'll try to do better next time. :)

Regards,
Marti