Re: string_agg distinct order by

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: string_agg distinct order by
Дата
Msg-id CAKFQuwa8j1wT=u__3RCYbqA6RvdvPKJ91b2_kwPtspUdO0pbHQ@mail.gmail.com
обсуждение исходный текст
Ответ на string_agg distinct order by  ("Markhof, Ingolf" <ingolf.markhof@de.verizon.com>)
Список pgsql-general
On Thu, Aug 19, 2021 at 9:09 AM Markhof, Ingolf <ingolf.markhof@de.verizon.com> wrote:
>
>
> string_agg(distinct status,',' order by status) as list
>
> but this is not what I want: 'green' would get first, red second, yellow last...
>
> I could also drop the distinct and say:
>
> string_agg(status,',' order by val_a) as list
>
> Any pointers?
>

public.function_that_converts_the_array_to_a_string_while_replacing_the_val_a_values_with_their_text_equivalent(array_agg(distinct val_a order by val_a))

Distinct is fairly simple - it sorts the data then skips over duplicates as they appear.  It needs a sort, applied implicitly or explicitly, to put the data in order.  If the sort is explicit it requires you to ensure that the distinct field values are all grouped together (it will do this itself if it adds an implied sort).

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: Rob Sargent
Дата:
Сообщение: Re: Selecting table row with latest date
Следующее
От: Tom Lane
Дата:
Сообщение: Re: string_agg distinct order by