Re: array_dims array_lower/upper distance

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Guy Fraser <guy(at)incentre(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: array_dims array_lower/upper distance
Date: 2005-09-23 02:52:51
Message-ID: 20050923025251.GA12881@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Sep 22, 2005 at 14:16:48 -0600,
Guy Fraser <guy(at)incentre(dot)net> wrote:
> On Thu, 2005-22-09 at 12:43 -0400, Greg Stark wrote:
> > Guy Fraser <guy(at)incentre(dot)net> writes:
> >
> > > So to answer his question he would likely want :
> > >
> > > SELECT
> > > array_upper(item,1) - array_upper(item,0) + 1 as elements
> > > FROM
> > > arraytest ;
> >
> > Note that this doesn't work for empty arrays.
> > It will return NULL instead of 0.
> Your response was not at all helpfull, I would like to
> encourage you to expand on what I put off the top of my
> head.
>
> I have not used array_upper() before, and the question was
> how to return the total number of elements, not how to
> handle NULL and empty arrays.

I think his point was that your example was going to give the wrong answer
for empty arrays, which is relevant to your question. The normal way around
that is to use the COALESCE function.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2005-09-23 03:01:23 Re: Questions about Rollback - after insert, update, delete ... operations?
Previous Message Bruce Momjian 2005-09-23 02:24:02 Re: PQtrace doesn't work