pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Markhof, Ingolf <ingolf.markhof@de.verizon.com>
Cc: pgsql-general@postgresql.org
Subject: Re: string_agg distinct order by
Date: Thu, 19 Aug 2021 12:30:45 -0400
Message-ID: <1761171.1629390645@sss.pgh.pa.us> (raw)
In-Reply-To: <CALZg0g5XLwoqFXsiC05SBiaCZhcB1QXDairtz+Hexf-NSCXPTw@mail.gmail.com>
References: <CALZg0g5XLwoqFXsiC05SBiaCZhcB1QXDairtz+Hexf-NSCXPTw@mail.gmail.com>

"Markhof, Ingolf" <ingolf.markhof@de.verizon.com> writes:
> I am looking for something like
> string_agg(distinct col_x order by col_y)

> Unfortunately, you can either have the distinct, but then the order by
> needs to be identical to what's aggregated, or you can have the order be
> determined by another column. Not both...

The reason for that restriction is that the case you propose is
ill-defined.  If we combine rows with the same col_x, which row's
value of col_y is to be used to sort the merged row?  I think once
you answer that question, a suitable query will suggest itself.

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <1761171.1629390645@sss.pgh.pa.us>
Permalink:  ../1761171.1629390645@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1761171.1629390645@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ingolf.markhof@de.verizon.com
  Subject: Re: string_agg distinct order by
  In-Reply-To: <1761171.1629390645@sss.pgh.pa.us>
  References: <CALZg0g5XLwoqFXsiC05SBiaCZhcB1QXDairtz+Hexf-NSCXPTw@mail.gmail.com> <1761171.1629390645@sss.pgh.pa.us>

* 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