Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cPANt-00086b-Ue for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Jan 2017 15:55:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cPANt-00086M-Fq for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Jan 2017 15:55:21 +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_2) (envelope-from ) id 1cPANr-00082J-D3 for pgsql-bugs@postgresql.org; Thu, 05 Jan 2017 15:55:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cPANo-0002S6-7Q for pgsql-bugs@postgresql.org; Thu, 05 Jan 2017 15:55:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v05FtDr7017090; Thu, 5 Jan 2017 10:55:13 -0500 From: Tom Lane To: Andrew Gierth cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14487: malformed empty array from array_fill In-reply-to: <874m1d1q1b.fsf@news-spur.riddles.org.uk> References: <20170105152156.10135.64195@wrigleys.postgresql.org> <874m1d1q1b.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Thu, 05 Jan 2017 15:33:19 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17088.1483631713.1@sss.pgh.pa.us> Date: Thu, 05 Jan 2017 10:55:13 -0500 Message-ID: <17089.1483631713@sss.pgh.pa.us> X-Pg-Spam-Score: -5.1 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Andrew Gierth writes: > "andrew" == andrew writes: > andrew> array_fill returns a malformed empty array when given a size of > andrew> zero: > Also, why does array_fill reject the case of an empty array of > dimensions? It seems obvious that it should return an empty array > result in such cases. Yeah. The code seems to have been intending to allow that: ndims = ARR_DIMS(dims)[0]; if (ndims < 0) /* we do allow zero-dimension arrays */ but it doesn't work right, precisely because that case comes out as being zero-dimensional not one dimension of length 0. Ideally I think we would reject zeroes in the lengths array as being an error, but it's probably too late for that, because likely people are using array[0] to get an empty result array since '{}' doesn't work. It also strikes me that this restriction is quite pointless: if (ARR_LBOUND(dims)[0] != 1) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), errmsg("wrong range of array subscripts"), errdetail("Lower bound of dimension array must be one."))); I think it's reasonable to disallow multi-dimensional input arrays here, but I don't see why it matters what the LB is. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs