| From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
|---|---|
| To: | fabriziomello(at)gmail(dot)com |
| Cc: | Bob Pawley <rjpawley(at)shaw(dot)ca>, Postgresql <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Arrays |
| Date: | 2011-09-14 18:09:27 |
| Message-ID: | CAHyXU0y_JC3iBTR2KqKsw5ex-VPRALY5aZVvKiurbYdYaTwVmA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Wed, Sep 14, 2011 at 1:05 PM, Fabrízio de Royes Mello
<fabriziomello(at)gmail(dot)com> wrote:
>
> 2011/9/14 Bob Pawley <rjpawley(at)shaw(dot)ca>
>>
>> Hi
>>
>> Is there a method of counting the number of elements in an array??
>>
>
> Yes...
> Use function array_upper [1].
> See an example:
> postgres(at)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Merlin Moncure | 2011-09-14 18:13:47 | Re: Identifying Reason for Column Name Returned by SELECT |
| Previous Message | Fabrízio de Royes Mello | 2011-09-14 18:05:08 | Re: Arrays |