Re: Arrays

From: Marti Raudsepp <marti(at)juffo(dot)org>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: Bob Pawley <rjpawley(at)shaw(dot)ca>, Postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Arrays
Date: 2011-09-17 03:11:48
Message-ID: CABRT9RBDRgPYRvpek44EVH1-+efnVoGHVCKJ-mzD=S5idEPfKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Sep 14, 2011 at 21:05, Fabrízio de Royes Mello
<fabriziomello(at)gmail(dot)com> wrote:
> postgres(at)bdteste=# SELECT array_upper(ARRAY['foo', 'bar'], 1);

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

On Wed, Sep 14, 2011 at 21:15, Steve Crawford
<scrawford(at)pinpointresearch(dot)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

In response to

  • Re: Arrays at 2011-09-14 18:15:07 from Steve Crawford

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2011-09-17 03:18:59 Re: Apparent Problem With NULL in Restoring pg_dump
Previous Message Adrian Klaver 2011-09-17 02:29:48 Re: RES: Foreign PostgreSQL server