Lists: | pgsql-general |
---|
From: | &ru <voros(dot)andras(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | number of dimensions of a multi-dimensional array |
Date: | 2005-12-01 13:15:39 |
Message-ID: | a2c1cdef0512010515ob1b04a0v@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hi!
I am developing pl/pgsql functions with multi-dimensional array input
parameter.
I can use array_dims(), but it gives just the text representation of
the structure and it is not suitable when I want to iterate over the
whole array with the array_lower() and array_upper() functions. I want
to handle custom dimension/size arrays.
So my question is, how can I easily determine the number of the
dimensions of an array?
Thanks,
Andrew
From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | Andrew <voros(dot)andras(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: number of dimensions of a multi-dimensional array |
Date: | 2005-12-02 03:42:05 |
Message-ID: | 20051202034205.GB12154@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Thu, Dec 01, 2005 at 02:15:39PM +0100, &ru wrote:
> Hi!
>
> I am developing pl/pgsql functions with multi-dimensional array input
> parameter.
> I can use array_dims(), but it gives just the text representation of
> the structure and it is not suitable when I want to iterate over the
> whole array with the array_lower() and array_upper() functions. I want
> to handle custom dimension/size arrays.
> So my question is, how can I easily determine the number of the
> dimensions of an array?
This illustrates what to do :)
SELECT
array_dims(array[[1,2],[3,4]]) AS "text representation",
string_to_array( array_dims(array[[1,2],[3,4]]) ,'][') AS "pieces",
array_upper( string_to_array( array_dims(array[[1,2],[3,4]]) ,']['), 1) AS "number of dimensions"
;
Cheers,
D
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 415 235 3778
Remember to vote!