Re: SELECT, GROUP BY, and aggregates

From: Bill Moran <wmoran(at)potentialtech(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Ryan Delaney <ryan(dot)delaney(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: SELECT, GROUP BY, and aggregates
Date: 2015-02-13 18:57:22
Message-ID: 20150213135722.c14ad1415eaa798f7354b7d6@potentialtech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 13 Feb 2015 10:48:13 -0800
Jeff Janes <jeff(dot)janes(at)gmail(dot)com> wrote:

> On Fri, Feb 13, 2015 at 10:26 AM, Bill Moran <wmoran(at)potentialtech(dot)com>
> wrote:
>
> > > Ryan Delaney <ryan(dot)delaney(at)gmail(dot)com> writes:
> > > > 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?
> >
> > I'm Mr. Curious today ...
> >
> > Why would you think that such a thing is necessary or desirable? Simply
> > add the
> > columns to the GROUP BY clause and make the request unambiguous.
>
> Where would the ambiguity be?

With a large, complex query, trying to visually read through a list of
column selections to figure out which ones _aren't_ aggregated and will
be auto-GROUP-BYed would be ... tedious and error prone at best.

You're right, though, it wouldn't be "ambiguous" ... that was a poor
choice of words on my part.

> I waste an inordinate amount of time retyping select lists over into the
> group by list, or copying and pasting and then deleting the aggregate
> clauses.

Interesting ... I've never kept accurate track of the time I spend doing
things like that, but "inordinate" seems like quite a lot.

In my case, I'm a developer so I would tend toward creating code on the
client side that automatically compiled the GROUP BY clause if I found
that scenarios like you describe were happening frequently. Of course,
that doesn't help a data anaylyst who's just writing queries

> It is an entirely pointless exercise. I can't fault PostgreSQL
> for following the standard, but its too bad the standards aren't more
> sensible.

I can't speak to the standard and it's reasons for doing this, but there
are certainly some whacko things in the standard.

Thanks for the response.

--
Bill Moran

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Brian Dunavant 2015-02-13 19:11:04 Re: SELECT, GROUP BY, and aggregates
Previous Message Vasudevan, Ramya 2015-02-13 18:53:42 Re: Question on session_replication_role