Search Postgresql Archives

Re: array sort for varchar arrays?

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

 



2008/7/8 Matthew Dennis <mdennis@xxxxxxxxxx>:
> I'm likely overlooking something, but I can't seem to find a function to
> sort a varchar array.  Something like "select sort('{y,z,x}'::varchar[])" =>
> {'x','y','z'}.
>

create function sort(anyarray)
returns anyarray as $$
select array(select $1[i] from generate_series(array_lower($1,1),
array_upper($1,1)) g(i) order by 1)
$$ language sql strict immutable;

postgres=# select sort(array[1,2,3,1]);
   sort
-----------
 {1,1,2,3}
(1 row)

postgres=# select sort(array['a','b','c','a']);
   sort
-----------
 {a,a,b,c}
(1 row)

Regards
Pavel Stehule


[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 Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux