Return last value in of array (PostgreSQL 7.2.1) - Mailing list pgsql-admin

From Erwin Brandstetter
Subject Return last value in of array (PostgreSQL 7.2.1)
Date
Msg-id Xns93FEE319E24A4BrandstetterFalterat@213.129.232.14
Whole thread Raw
Responses Re: Return last value in of array (PostgreSQL 7.2.1)  (Steve Crawford <scrawford@pinpointresearch.com>)
List pgsql-admin
Hi Newsgroup!

I can't believe I have found a good solution here. I want to return the
last value of an array with an SQL statement, while I do not know, how many
items the array holds (u can never be sure of that since u can redim an
array in PostgreSQL whenever u like..).

That is what i came up with:


select my_array_field[substr(array_dims(my_array_field), 4, 1)]
from my_table;


But this only works, as long as the upper boundary is from 1 to 9 (one
digit). Besides it looks ugly and will perform likewise.

Did I miss something here?
Is there any function returning more sensible data than array_dims
(returning something like '[1:4]')?

Grateful for any hints.
Regards
Erwin Brandstetter

--
no z in my mail.

pgsql-admin by date:

Previous
From: "Nick Fankhauser - Doxpop"
Date:
Subject: PG version for n_distinct question.
Next
From: Steve Crawford
Date:
Subject: Re: Return last value in of array (PostgreSQL 7.2.1)