Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL) - Mailing list pgsql-docs

From Bruce Momjian
Subject Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)
Date
Msg-id 20151130235919.GC19371@momjian.us
Whole thread Raw
In response to Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)  (Michael Herold <quabla@hemio.de>)
Responses Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)  (Michael Herold <quabla@hemio.de>)
List pgsql-docs
On Mon, Oct 26, 2015 at 11:04:40AM +0100, Michael Herold wrote:
> I just got confused by another behavior of the || operator. I
> thought it might be appropriate to report it here.
>
> The docs say "the result retains the lower bound subscript of the
> left-hand operand’s outer dimension" [1]. That's again not true for
> corner cases.

You didn't quote the entire sentence:

    When two arrays with an equal number of dimensions are concatenated, the
    -------------------------------------------------------------------
    result retains the lower bound subscript of the left-hand operand's
    outer dimension.

> Expected:
> # SELECT '{0}'::int[] || '[15:16]={1,2}';
> ----------
>  {0,1,2}
>
> Unexpected (lower bound is untouched):
> # SELECT '{}'::int[] || '[15:16]={1,2}';
> ---------------
>  [15:16]={1,2}

I would argue that '{}'::int[] is zero dimmensions, so there is no
documented behavior for this.

The C code is:

    /*
     * short circuit - if one input array is empty, and the other is not, we
     * return the non-empty one as the result
     *
     * if both are empty, return the first one
     */
    if (ndims1 == 0 && ndims2 > 0)
        PG_RETURN_ARRAYTYPE_P(v2);

I doubt we want to change this.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription                             +


pgsql-docs by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: pg_rewind source-server connection
Next
From: Bruce Momjian
Date:
Subject: Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)