From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14487: malformed empty array from array_fill
Date: Thu, 05 Jan 2017 10:55:13 -0500
Message-ID: <17089.1483631713@sss.pgh.pa.us> (raw)
In-Reply-To: <874m1d1q1b.fsf@news-spur.riddles.org.uk>
References: <20170105152156.10135.64195@wrigleys.postgresql.org>
<874m1d1q1b.fsf@news-spur.riddles.org.uk>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> "andrew" == andrew <andrew@tao11.riddles.org.uk> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, andrew@tao11.riddles.org.uk
Subject: Re: BUG #14487: malformed empty array from array_fill
In-Reply-To: <17089.1483631713@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox