Re: Why can't I select un-grouped columns when grouping by a (non-primary) unique key? - Mailing list pgsql-general

From Daniel Lenski
Subject Re: Why can't I select un-grouped columns when grouping by a (non-primary) unique key?
Date
Msg-id CAOw_LSGWP1kSs6BhUS0f2ngb=Cckm3MwN6Q9Wm77Jadpz10S7A@mail.gmail.com
Whole thread Raw
In response to Re: Why can't I select un-grouped columns when grouping by a (non-primary) unique key?  (Alberto Cabello Sánchez <alberto@unex.es>)
List pgsql-general
On Wed, Sep 24, 2014 at 10:37 AM, Alberto Cabello Sánchez
<alberto@unex.es> wrote:
> At first sight, primary key means no grouping at all, as there are no
> duplicated A.primary_key values:
>
>   SELECT A.document
>     FROM A
>     GROUP BY A.primary_key
>
> is the same as
>
>   SELECT A.document
>     FROM A
>

Yes, my example is oversimplified, because GROUP BY primary_key has no
semantic effect on a single-table query, although it still illustrates
the different behavior for PRIMARY KEY vs. UNIQUE NOT NULL, which
should be logically equivalent.

The examples that Geoff Montee gave are better because (GROUP BY
primary_key) does change the meaning of the query when there's a join
to another table.

Dan


pgsql-general by date:

Previous
From: Daniel Lenski
Date:
Subject: Re: Why can't I select un-grouped columns when grouping by a (non-primary) unique key?
Next
From: Tom Lane
Date:
Subject: Re: Why can't I select un-grouped columns when grouping by a (non-primary) unique key?