Re: Arrays - Mailing list pgsql-general

From Marti Raudsepp
Subject Re: Arrays
Date
Msg-id CABRT9RBDRgPYRvpek44EVH1-+efnVoGHVCKJ-mzD=S5idEPfKA@mail.gmail.com
Whole thread Raw
In response to Re: Arrays  (Steve Crawford <scrawford@pinpointresearch.com>)
List pgsql-general
On Wed, Sep 14, 2011 at 21:05, Fabrízio de Royes Mello
<fabriziomello@gmail.com> wrote:
> postgres@bdteste=# SELECT array_upper(ARRAY['foo', 'bar'], 1);

On Wed, Sep 14, 2011 at 21:09, Merlin Moncure <mmoncure@gmail.com> wrote:
> select count(*) from unnest(_array_);

On Wed, Sep 14, 2011 at 21:15, Steve Crawford
<scrawford@pinpointresearch.com> wrote:
> Look at array_dims, array_upper and array_lower.

Huh, what's up with people suggesting overcomplicated solutions?

Just use the one function that's designed to do this: array_length(arr, 1)
Note that for an empty array, this will return NULL. If you want to
get 0 instead, use:
coalesce(array_length(arr, 1), 0)

Note that, for multidimensional arrays, this returns the length of the
1st dimension (hence 1 in arguments)

Regards,
Marti

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: RES: Foreign PostgreSQL server
Next
From: Andy Colson
Date:
Subject: Re: Apparent Problem With NULL in Restoring pg_dump