Re: array_dims array_lower/upper distance

From: Guy Fraser <guy(at)incentre(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: array_dims array_lower/upper distance
Date: 2005-09-23 17:29:36
Message-ID: 1127496576.4437.72.camel@sigurd.incentre.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 2005-23-09 at 09:48 -0700, Matthew Peter wrote:
>
> --- Guy Fraser <guy(at)incentre(dot)net> wrote:
>
...snip...
> > OK what I jotted down was totally wrong.
> >
> > This is slightly more correct :
> >
> > SELECT
> > array_upper(item,1) - array_lower(item,1) + 1 as
> > elements
> > FROM
> > arraytest ;
> >
> > Without do a tonne of research, I can not refine
> > this to handle
> > all circumstances.
> >
> > Can someone point me to documentation that explains
> > the function
> > better than :
> >
> > Dimensions can also be retrieved with array_upper
> > and array_lower, which
> > return the upper and lower bound of a specified
> > array dimension,
> > respectively.
> >
> > The table "Table 9-36. array Functions" does not
> > explain how empty
> > and null arrays are handled either.
> >
> > How do array_upper() and array_lower() respond to :
> > 1) NULL
> > 2) Empty Array
> > 3) Nonexistent requested dimension
> >
> > Also is there a function that specifies how many
> > dimensions the
> > array has?
> >
>
> That was exactly the answer I was looking for when I
> posted the question. Now if there was a function to
> delete a position in the array....
>
> ie set array1 = array_delete_at(array1,5) where 5 is
> the position to delete

I hope someone else can answer that, the best I can do
is provide a link to the docs :

http://www.postgresql.org/docs/current/static/functions-array.html

My best guess is that you need to "walk" the array and
drop the element you don't want. The way I currently
use arrays is I read the whole array into my application
the modify the array then update the whole array.

Unfortunately the arrays in PG are not associative and the
elements must be sequential. I only use arrays in limited
ways in PG because of earlier constraints, and have not
needed to investigate the newer features.

Good luck.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2005-09-23 17:31:47 Re: PQtrace doesn't work
Previous Message Matthew Peter 2005-09-23 16:48:06 Re: array_dims array_lower/upper distance