Search Postgresql Archives

Re: Arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 14, 2011 at 1:05 PM, Fabrízio de Royes Mello
<fabriziomello@xxxxxxxxx> wrote:
>
> 2011/9/14 Bob Pawley <rjpawley@xxxxxxx>
>>
>> Hi
>>
>> Is there a method of counting the number of elements in an array??
>>
>
> Yes...
> Use function array_upper [1].
> See an example:
> postgres@bdteste=# SELECT array_upper(ARRAY['foo', 'bar'], 1);
>  array_upper
> -------------
>            2

that only gives you one dimension's worth elements, and only is
correct if the array is 1 based.

select count(*) from unnest(_array_);

will give you an exact count.  another way to do it which doesn't
require expanding the array would be to parse and calculate # elements
from the output of array_dims() (which is unfortunately returned as
text).

merlin

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux