Re: string_agg distinct order by - Mailing list pgsql-general

From Tom Lane
Subject Re: string_agg distinct order by
Date
Msg-id 1761171.1629390645@sss.pgh.pa.us
Whole thread Raw
In response to string_agg distinct order by  ("Markhof, Ingolf" <ingolf.markhof@de.verizon.com>)
Responses Re: [E] Re: string_agg distinct order by  ("Markhof, Ingolf" <ingolf.markhof@de.verizon.com>)
List pgsql-general
"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



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: string_agg distinct order by
Next
From: Rich Shepard
Date:
Subject: Re: Selecting table row with latest date