Re: pl/pgsql uniq varchar[] sort? - Mailing list pgsql-general

From Merlin Moncure
Subject Re: pl/pgsql uniq varchar[] sort?
Date
Msg-id b42b73150604030810r3716ff33pe20ddc9169267176@mail.gmail.com
Whole thread Raw
In response to pl/pgsql uniq varchar[] sort?  (Matthew Peter <survivedsushi@yahoo.com>)
Responses Re: sort a referenced list
List pgsql-general
On 4/3/06, Matthew Peter <survivedsushi@yahoo.com> wrote:
>
>  Hello list. I'm trying to get a unique, sorted varchar array in pl/pgsql.
> Essentially a "group by" and "order by"'d varchar[].
>
>  Anyone got any ideas or point me in the right direction? Thanks.

If your data is not an array type coming off the table but you want it
to end up that way, check out array_accum at
http://www.postgresql.org/docs/8.1/static/xaggr.html.  All you have to
do is order the data going into the aggregate:

select array_accum(d) from
(
  select d from t order by...
)

if your data is starting off as an array type, you have a few options.
 you might get the most milage out of a pl/perl procedure to sort the
type.  If the arrays are small and you absolutely had to do it in
plpgsql you could copy the values into a temp table, sort it via
query, and resinsert into an array using the above technique.

merlin

pgsql-general by date:

Previous
From: "William Leite Araújo"
Date:
Subject: Re: How to delete all operators
Next
From: Richard Broersma Jr
Date:
Subject: Re: database design questions