From: Steve Crawford <scrawford@pinpointresearch.com>
To: Erwin Brandstetter <Brsaz@gmzx.at>
To: pgsql-admin@postgresql.org
Subject: Re: Return last value in of array (PostgreSQL 7.2.1)
Date: Tue, 23 Sep 2003 17:46:13 -0700
Message-ID: <200309231746.13757.scrawford@pinpointresearch.com> (raw)
In-Reply-To: <Xns93FEE319E24A4BrandstetterFalterat@213.129.232.14>
References: <Xns93FEE319E24A4BrandstetterFalterat@213.129.232.14>
> 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...
> 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]')?
IIRC I heard talk of new max and min array dimension functions in
upcoming releases. I'm tired so there may be better or more elegant
solutions but this one works (r is the array):
r[rtrim(substring(array_dims(r), position(':' in
array_dims(r))+1),']')::int]
Cheers,
Steve
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: scrawford@pinpointresearch.com, Brsaz@gmzx.at
Subject: Re: Return last value in of array (PostgreSQL 7.2.1)
In-Reply-To: <200309231746.13757.scrawford@pinpointresearch.com>
References: <Xns93FEE319E24A4BrandstetterFalterat@213.129.232.14> <200309231746.13757.scrawford@pinpointresearch.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox