array size

Started by akp geekabout 15 years ago4 messagesgeneral
Jump to latest
#1akp geek
akpgeek@gmail.com

Hi all -

I am trying to find the number of elements in the array. Right
now I am using array_upper and array_lower. Is there any other way of
getting the number of elements?

thanks for the help

Regards

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: akp geek (#1)
Re: array size

It may help to specify why you feel that array_upper and array_lower are
insufficient for your use. I mean, you could " count( unnest( array ) ) "
but whether that is better or worse than array_upper really depends on your
needs.

David J.

From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of akp geek
Sent: Thursday, February 24, 2011 2:17 PM
To: pgsql-general
Subject: [GENERAL] array size

Hi all -

I am trying to find the number of elements in the array. Right
now I am using array_upper and array_lower. Is there any other way of
getting the number of elements?

thanks for the help

Regards

#3Dmitriy Igrishin
dmitigr@gmail.com
In reply to: akp geek (#1)
Re: array size

Hey,

2011/2/24 akp geek <akpgeek@gmail.com>

Hi all -

I am trying to find the number of elements in the array.
Right now I am using array_upper and array_lower. Is there any other way of
getting the number of elements?

You may use array_length() function, e.g.
dmitigr=> SELECT array_length(ARRAY[ARRAY[1,2,3],ARRAY[4,5,6]], 1);
array_length
--------------
2
(1 row)

dmitigr=> SELECT array_length(ARRAY[ARRAY[1,2,3],ARRAY[4,5,6]], 2);
array_length
--------------
3
(1 row)

See http://www.postgresql.org/docs/9.0/static/functions-array.html

thanks for the help

Regards

--
// Dmitriy.

#4akp geek
akpgeek@gmail.com
In reply to: Dmitriy Igrishin (#3)
Re: array size

Unfortunately the our database is still 8.3. that's a limitation for using
array_length

Regards

On Thu, Feb 24, 2011 at 4:08 PM, Dmitriy Igrishin <dmitigr@gmail.com> wrote:

Show quoted text

Hey,

2011/2/24 akp geek <akpgeek@gmail.com>

Hi all -

I am trying to find the number of elements in the array.
Right now I am using array_upper and array_lower. Is there any other way of
getting the number of elements?

You may use array_length() function, e.g.
dmitigr=> SELECT array_length(ARRAY[ARRAY[1,2,3],ARRAY[4,5,6]], 1);
array_length
--------------
2
(1 row)

dmitigr=> SELECT array_length(ARRAY[ARRAY[1,2,3],ARRAY[4,5,6]], 2);
array_length
--------------
3
(1 row)

See http://www.postgresql.org/docs/9.0/static/functions-array.html

thanks for the help

Regards

--
// Dmitriy.