Re: array_dims array_lower/upper distance

Поиск
Список
Период
Сортировка
От Matthew Peter
Тема Re: array_dims array_lower/upper distance
Дата
Msg-id 20050923164806.42169.qmail@web35210.mail.mud.yahoo.com
обсуждение исходный текст
Ответ на Re: array_dims array_lower/upper distance  (Guy Fraser <guy@incentre.net>)
Ответы Re: array_dims array_lower/upper distance  (Guy Fraser <guy@incentre.net>)
Список pgsql-general

--- Guy Fraser <guy@incentre.net> wrote:

> On Thu, 2005-22-09 at 21:52 -0500, Bruno Wolff III
> wrote:
> > On Thu, Sep 22, 2005 at 14:16:48 -0600,
> >   Guy Fraser <guy@incentre.net> wrote:
> > > On Thu, 2005-22-09 at 12:43 -0400, Greg Stark
> wrote:
> > > > Guy Fraser <guy@incentre.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.
> 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


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

В списке pgsql-general по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: SQL command to dump the contents of table failed: PQendcopy() failed. Error message from server: socket not open
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: PQtrace doesn't work