Re: string_agg distinct order by

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Markhof, Ingolf" <ingolf(dot)markhof(at)de(dot)verizon(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: string_agg distinct order by
Date: 2021-08-19 16:30:45
Message-ID: 1761171.1629390645@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Markhof, Ingolf" <ingolf(dot)markhof(at)de(dot)verizon(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2021-08-19 16:31:50 Re: Selecting table row with latest date
Previous Message David G. Johnston 2021-08-19 16:30:00 Re: string_agg distinct order by