pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vik Fearing <vik@postgresfriends.org>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: GROUP BY DISTINCT
Date: Sun, 21 Feb 2021 13:52:24 +0100
Message-ID: <bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org> (raw)

When combining multiple grouping items, such as rollups and cubes, the
resulting flattened grouping sets can contain duplicate items.  The
standard provides for this by allowing GROUP BY DISTINCT to deduplicate
them prior to doing the actual work.

For example:
GROUP BY ROLLUP (a,b), ROLLUP (a,c)

expands to the sets:
(a,b,c), (a,b), (a,b), (a,c), (a), (a), (a,c), (a), ()

but:
GROUP BY DISTINCT ROLLUP (a,b), ROLLUP (a,c)

expands to just the sets:
(a,b,c), (a,b), (a,c), (a), ()

Attached is a patch to implement this for PostgreSQL.
-- 
Vik Fearing

Attachments:

  [text/x-patch] 0001-implement-GROUP-BY-DISTINCT.v01.patch (0B, ../bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org/2-0001-implement-GROUP-BY-DISTINCT.v01.patch)
  download

view thread (20+ messages)  latest in thread

Message-ID: <bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org>
Permalink:  ../bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org/
Also on:    postgresql.org/message-id/bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: vik@postgresfriends.org, pgsql-hackers@lists.postgresql.org
  Subject: Re: GROUP BY DISTINCT
  In-Reply-To: <bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox