pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14487: malformed empty array from array_fill
3+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2017-01-05 82f8107b92 5b4f8f4c6d 4555a375a1 4e446563be ee9cb284a6 e0d59c6ef5 Fix handling of empty arrays in array_fill().
* BUG #14487: malformed empty array from array_fill
@ 2017-01-05 15:21 andrew@tao11.riddles.org.uk
2017-01-05 15:33 ` Re: BUG #14487: malformed empty array from array_fill Andrew Gierth <andrew@tao11.riddles.org.uk>
0 siblings, 1 reply; 3+ messages in thread
From: andrew@tao11.riddles.org.uk @ 2017-01-05 15:21 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14487
Logged by: Andrew Gierth
Email address: andrew@tao11.riddles.org.uk
PostgreSQL version: 9.6.1
Operating system: any
Description:
array_fill returns a malformed empty array when given a size of zero:
select a, a = '{}' from (select array_fill(null::integer, array[0]) as a)
s;
a | ?column?
----+----------
{} | f
The result actually has ndims=1 and a length of 0, which can be checked with
array_length(a,1).
Obvious fix is to move the fast-track empty result to after computing
nitems?
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #14487: malformed empty array from array_fill
2017-01-05 15:21 BUG #14487: malformed empty array from array_fill andrew@tao11.riddles.org.uk
@ 2017-01-05 15:33 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2017-01-05 15:55 ` Re: BUG #14487: malformed empty array from array_fill Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Gierth @ 2017-01-05 15:33 UTC (permalink / raw)
To: pgsql-bugs
>>>>> "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.
--
Andrew (irc:RhodiumToad)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #14487: malformed empty array from array_fill
2017-01-05 15:21 BUG #14487: malformed empty array from array_fill andrew@tao11.riddles.org.uk
2017-01-05 15:33 ` Re: BUG #14487: malformed empty array from array_fill Andrew Gierth <andrew@tao11.riddles.org.uk>
@ 2017-01-05 15:55 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2017-01-05 15:55 UTC (permalink / raw)
To: Andrew Gierth <andrew@tao11.riddles.org.uk>; +Cc: pgsql-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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2017-01-05 15:55 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-01-05 15:21 BUG #14487: malformed empty array from array_fill andrew@tao11.riddles.org.uk
2017-01-05 15:33 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2017-01-05 15:55 ` Tom Lane <tgl@sss.pgh.pa.us>
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