Hi @ThomazRossito 

Thanks for your response and Sorry for my late reply.

I apologize that my question did not accurately describe my scenario.

It is true that the `sort_array` function works well for this sample data.

On the other hand, array values do not necessarily have rules like alphabetical or numeric.

------------------------------

with tmp as (
select * from (values
(1, 1, 'cherry'),
(1, 3, 'strawberries'),
(1, 2, 'acerola'),
(1, 5, 'banan'),
(1, 4, 'lemon')
) as tab(custid, hist, alf)
order by custid asc, hist asc
)
select
custid,
array_join(array_agg(alf), ' -> ') as move
from tmp
group by custid
order by custid asc;

------------------------------

I would like to get array like `[cherry -> acerola -> strawberries -> lemon -> banan]` for above sample data. I would like to sort and keep the array values according to the order of the `hist` columns but `array_agg()` states `The order of elements in the array is non-deterministic`.

If you have a solution, I would appreciate your response!