Re: Sorting items in aggregate function

From: Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr>
To: Steven Murdoch <psql+Steven(dot)Murdoch(at)cl(dot)cam(dot)ac(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sorting items in aggregate function
Date: 2006-09-12 18:24:39
Message-ID: 20060912182439.GB1373@alamut
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sep 12 04:46, Steven Murdoch wrote:
> I would like to concatenate sorted strings in an aggregate function. I
> found a way to do it without sorting[1], but not with.

If the array elements will be made of integers, then you can use sort()
procedure comes with intarray contrib module. For instance,

SELECT concat(T.sorted_arr)
FROM (SELECT sort(arr) FROM tbl) AS T (sorted_arr);

If related column will also include text values, you can create a
suitable sort() procedure for text[] type and use it instead.

Regards.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2006-09-12 18:46:30 Re: Two optimization questions
Previous Message Aaron Bono 2006-09-12 18:21:35 Re: on connect/on disconnect