Re: number of elements in a multidimensional array

Lists: pgsql-general
From: "SunWuKung" <Balazs(dot)Klein(at)t-online(dot)hu>
To: pgsql-general(at)postgresql(dot)org
Subject: number of elements in a multidimensional array
Date: 2006-08-31 15:17:35
Message-ID: 1157037455.753385.91450@p79g2000cwp.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

>From this array how could I get back the fact that this array consists
of a two dimensional array with X elements?

Select array_dims('{{1,4,10,11},{1,5,4,5}}'::text [])

I would like to get back the number 4 here?

Thanks for the help.
Balázs


From: "SunWuKung" <Balazs(dot)Klein(at)t-online(dot)hu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: number of elements in a multidimensional array
Date: 2006-09-01 10:42:30
Message-ID: 1157107350.264541.114260@p79g2000cwp.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


SunWuKung wrote:
> >From this array how could I get back the fact that this array consists
> of a two dimensional array with X elements?
>
> Select array_dims('{{1,4,10,11},{1,5,4,5}}'::text [])
>
> I would like to get back the number 4 here?
>
> Thanks for the help.
> Balázs

This is what I came up with finally, not very elegant but seems to do
the job:
Select substring(array_dims('{{1,4,10,11},{1,5,4,5}}'::text []) from
'([0-9]*)]$')


From: David Fetter <david(at)fetter(dot)org>
To: SunWuKung <Balazs(dot)Klein(at)t-online(dot)hu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: number of elements in a multidimensional array
Date: 2006-09-01 18:47:37
Message-ID: 20060901184737.GR7270@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Aug 31, 2006 at 08:17:35AM -0700, SunWuKung wrote:
> From this array how could I get back the fact that this array
> consists of a two dimensional array with X elements?
>
> Select array_dims('{{1,4,10,11},{1,5,4,5}}'::text [])
>
> I would like to get back the number 4 here?

SELECT array_upper('{{1,4,10,11},{1,5,4,5}}'::TEXT[], 2);

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!