Search Postgresql Archives

Re: string_agg distinct order by

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 19, 2021 at 9:09 AM Markhof, Ingolf <ingolf.markhof@xxxxxxxxxxxxxx> 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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux