From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Mike Martin <mike(at)redtux(dot)plus(dot)com> |
Cc: | pgsql-sql(at)lists(dot)postgresql(dot)org |
Subject: | Re: Ordering of arrays |
Date: | 2019-08-23 11:53:45 |
Message-ID: | CAFj8pRALiF2VPVuo-CYXobtyr45tdT7mSbj7GZyR+kUbJ1ru_w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi
pá 23. 8. 2019 v 12:48 odesílatel Mike Martin <mike(at)redtux(dot)plus(dot)com> napsal:
> A question about arrays.
> Is iit possible to reverse an array array?
> for example
> regexp_split_to_array(/srv/progs/programs/Aliens/The_Aliens_1_ens_envsc2_envsc2.mp4,'('/|\.)'),
> which splits on either / or . to extract fileparts
>
> It would be useful to be able to have the array returned reversed, so
> rather than having to use cardinality(array)-1 I have a reversed array and
> say arr[1]
> Also it seems impossible to get a reverse slice (returns null array)
>
you can use own simple function
create or replace function array_rvrs(anyarray)
returns anyarray as $$
select array(select unnest from unnest($1) with ordinality order by
ordinality desc)
$$ language sql immutable strict;
postgres=# select array_rvrs(ARRAY[10, 20, 30, 1, 2, 3]);
┌──────────────────┐
│ array_rvrs │
╞══════════════════╡
│ {3,2,1,30,20,10} │
└──────────────────┘
(1 row)
Regards
Pavel
>
> thanks
>
From | Date | Subject | |
---|---|---|---|
Next Message | Sebastien FLAESCH | 2019-08-29 16:32:44 | libpq: How are result sets fetch behind the scene? |
Previous Message | Mike Martin | 2019-08-23 10:14:49 | Ordering of arrays |