pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedArray dimension lost if dimension length is zero
7+ messages / 3 participants
[nested] [flat]
* Array dimension lost if dimension length is zero
@ 2016-09-08 17:25 Shay Rojansky <roji@roji.org>
0 siblings, 1 reply; 7+ messages in thread
From: Shay Rojansky @ 2016-09-08 17:25 UTC (permalink / raw)
To: pgsql-bugs
An Npgsql user has reported an edge case use which seems to be a bug.
When sending a multidimensional array to PostgreSQL, if the length of a
dimension is 0, that dimension is lost. That is, the user sends a
2-dimensional array with 0 for both dimensions; trying to read this back
will return a 1-dimensional array.
It seems that another way to see this problem is this... Running "select
ARRAY[[1], [1]]::integer[]" returns "{{1},{1}}". However, running "select
ARRAY[[], []]::integer[]" returns "{}".
It seems important for the dimensionality of the array to be what was sent
regardless of the lengths; otherwise problems occur as the user expect back
a 2-dimensional array but receive a single-dimensional one...
For reference, the original issue is
https://github.com/npgsql/npgsql/issues/1271
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Array dimension lost if dimension length is zero
@ 2016-09-08 17:32 Tom Lane <tgl@sss.pgh.pa.us>
parent: Shay Rojansky <roji@roji.org>
0 siblings, 2 replies; 7+ messages in thread
From: Tom Lane @ 2016-09-08 17:32 UTC (permalink / raw)
To: Shay Rojansky <roji@roji.org>; +Cc: pgsql-bugs
Shay Rojansky <roji@roji.org> writes:
> An Npgsql user has reported an edge case use which seems to be a bug.
> When sending a multidimensional array to PostgreSQL, if the length of a
> dimension is 0, that dimension is lost. That is, the user sends a
> 2-dimensional array with 0 for both dimensions; trying to read this back
> will return a 1-dimensional array.
This is intentional: all empty arrays are alike, with zero dimensions
(not one dimension, but none).
Probably a lot of these decisions would be made differently if we were
starting over in a green field; but since we're not, I'm disinclined
to touch it.
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] 7+ messages in thread
* Re: Array dimension lost if dimension length is zero
@ 2016-09-08 19:31 Shay Rojansky <roji@roji.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 7+ messages in thread
From: Shay Rojansky @ 2016-09-08 19:31 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs
Ah, I see. And changing this in a major version is out of the question? It
makes dealing with arrays more complicated than it should be on the client
side etc.
On Thu, Sep 8, 2016 at 5:32 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Shay Rojansky <roji@roji.org> writes:
> > An Npgsql user has reported an edge case use which seems to be a bug.
> > When sending a multidimensional array to PostgreSQL, if the length of a
> > dimension is 0, that dimension is lost. That is, the user sends a
> > 2-dimensional array with 0 for both dimensions; trying to read this back
> > will return a 1-dimensional array.
>
> This is intentional: all empty arrays are alike, with zero dimensions
> (not one dimension, but none).
>
> Probably a lot of these decisions would be made differently if we were
> starting over in a green field; but since we're not, I'm disinclined
> to touch it.
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Array dimension lost if dimension length is zero
@ 2016-09-09 06:51 Shay Rojansky <roji@roji.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 7+ messages in thread
From: Shay Rojansky @ 2016-09-09 06:51 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs
>
> This is intentional: all empty arrays are alike, with zero dimensions
> (not one dimension, but none).
>
Also, note that when reading an empty array in binary encoding, the
dimension field contains one.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Array dimension lost if dimension length is zero
@ 2016-09-09 07:13 Andrew Gierth <andrew@tao11.riddles.org.uk>
parent: Shay Rojansky <roji@roji.org>
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Gierth @ 2016-09-09 07:13 UTC (permalink / raw)
To: Shay Rojansky <roji@roji.org>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs
>>>>> "Shay" == Shay Rojansky <roji@roji.org> writes:
>> This is intentional: all empty arrays are alike, with zero
>> dimensions (not one dimension, but none).
Shay> Also, note that when reading an empty array in binary encoding,
Shay> the dimension field contains one.
Nope:
postgres=# select array_send('{}'::integer[]);
array_send
----------------------------
\x000000000000000000000017
(that's ndim=00000000, flags=00000000, element_oid=00000017)
--
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] 7+ messages in thread
* Re: Array dimension lost if dimension length is zero
@ 2016-09-09 09:09 Shay Rojansky <roji@roji.org>
parent: Andrew Gierth <andrew@tao11.riddles.org.uk>
0 siblings, 1 reply; 7+ messages in thread
From: Shay Rojansky @ 2016-09-09 09:09 UTC (permalink / raw)
To: Andrew Gierth <andrew@tao11.riddles.org.uk>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs
Apologies, I misinterpreted the results.
I still think it may make sense to change this behavior in a major version
release, although I don't know what the PostgreSQL policy is on such
breakage.
On Fri, Sep 9, 2016 at 7:13 AM, Andrew Gierth <andrew@tao11.riddles.org.uk>
wrote:
> >>>>> "Shay" == Shay Rojansky <roji@roji.org> writes:
>
> >> This is intentional: all empty arrays are alike, with zero
> >> dimensions (not one dimension, but none).
>
> Shay> Also, note that when reading an empty array in binary encoding,
> Shay> the dimension field contains one.
>
> Nope:
>
> postgres=# select array_send('{}'::integer[]);
> array_send
> ----------------------------
> \x000000000000000000000017
>
> (that's ndim=00000000, flags=00000000, element_oid=00000017)
>
> --
> Andrew (irc:RhodiumToad)
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Array dimension lost if dimension length is zero
@ 2016-09-09 11:44 Tom Lane <tgl@sss.pgh.pa.us>
parent: Shay Rojansky <roji@roji.org>
0 siblings, 0 replies; 7+ messages in thread
From: Tom Lane @ 2016-09-09 11:44 UTC (permalink / raw)
To: Shay Rojansky <roji@roji.org>; +Cc: Andrew Gierth <andrew@tao11.riddles.org.uk>; pgsql-bugs
Shay Rojansky <roji@roji.org> writes:
> I still think it may make sense to change this behavior in a major version
> release, although I don't know what the PostgreSQL policy is on such
> breakage.
I think there's basically no chance of that happening. It would break an
enormous amount of code that currently isn't broken, to change to a
definition that's only arguably better than what we have.
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] 7+ messages in thread
end of thread, other threads:[~2016-09-09 11:44 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-09-08 17:25 Array dimension lost if dimension length is zero Shay Rojansky <roji@roji.org>
2016-09-08 17:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-08 19:31 ` Shay Rojansky <roji@roji.org>
2016-09-09 06:51 ` Shay Rojansky <roji@roji.org>
2016-09-09 07:13 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2016-09-09 09:09 ` Shay Rojansky <roji@roji.org>
2016-09-09 11:44 ` 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