Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a3YLu-0002QI-89 for pgsql-docs@arkaria.postgresql.org; Mon, 30 Nov 2015 23:59:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a3YLt-00053T-Mj for pgsql-docs@arkaria.postgresql.org; Mon, 30 Nov 2015 23:59:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a3YLt-00053M-A6 for pgsql-docs@postgresql.org; Mon, 30 Nov 2015 23:59:25 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1a3YLq-0006NR-9C for pgsql-docs@postgresql.org; Mon, 30 Nov 2015 23:59:24 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1a3YLn-00031Y-CG; Mon, 30 Nov 2015 18:59:19 -0500 Date: Mon, 30 Nov 2015 18:59:19 -0500 From: Bruce Momjian To: Michael Herold Cc: Tom Lane , pgsql-docs@postgresql.org Subject: Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL) Message-ID: <20151130235919.GC19371@momjian.us> References: <559DC0CE.90900@hemio.de> <32402.1436450457@sss.pgh.pa.us> <562DFAB8.9050507@hemio.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <562DFAB8.9050507@hemio.de> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org 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 http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Roman grave inscription + -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs