Return last value in of array (PostgreSQL 7.2.1)

From: Erwin Brandstetter <Brsaz(at)gmzx(dot)at>
To: pgsql-admin(at)postgresql(dot)org
Subject: Return last value in of array (PostgreSQL 7.2.1)
Date: 2003-09-22 20:21:10
Message-ID: Xns93FEE319E24A4BrandstetterFalterat@213.129.232.14
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Együd Csaba 2003-09-23 05:06:29 Craeting special backup
Previous Message Bruce Momjian 2003-09-22 18:46:27 Re: help needed!!!