From: | Tony Wasson <ajwasson(at)gmail(dot)com> |
---|---|
To: | Matthew Peter <survivedsushi(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: array_dims array_lower/upper distance |
Date: | 2005-09-21 14:48:36 |
Message-ID: | 6d8daee305092107484a5e217e@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 9/20/05, Matthew Peter <survivedsushi(at)yahoo(dot)com> wrote:
> Wondering if there's a way for postgres to return how
> many elements are in a array as a single integer? For
> instance, returning 10 (items in array) instead of
> [-5:4]
>
> Also, is there a way to return the position of an item
> in a array?
>
Try using array_upper and specify which array dimension.
from http://www.postgresql.org/docs/current/static/arrays.htm:
"array_dims produces a text result, which is convenient for people to
read but perhaps not so convenient for programs. Dimensions can also
be retrieved with array_upper and array_lower, which return the upper
and lower bound of a specified array dimension, respectively."
pg8=# SELECT array_dims('{4,2,3,5,6}'::INT[]);
array_dims
------------
[1:5]
(1 row)
pg8=# SELECT array_upper('{4,2,3,5,6}'::INT[],1);
array_upper
-------------
5
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-09-21 14:55:14 | Re: pg_index_indrelid_index error, any ideas ?? |
Previous Message | Belinda M. Giardine | 2005-09-21 14:09:38 | Re: running vacuum in scripts |