Re: Weird special case in jsonb_concat()
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2020-12-19T20:35:28Z
Lists: pgsql-hackers
Attachments
- fix-jsonb-concatenation-special-cases.patch (text/x-diff) patch
I wrote:
> However, further experimentation found a case that fails:
> regression=# select '3'::jsonb || '{}'::jsonb;
> ERROR: invalid concatenation of jsonb objects
> I wonder what is the point of this weird exception, and whether
> whoever devised it can provide a concise explanation of what
> they think the full behavior of "jsonb || jsonb" is. Why isn't
> '[3, {}]' a reasonable result here, if the cases above are OK?
Here is a proposed patch for that. It turns out that the third
else-branch in IteratorConcat() already does the right thing, if
we just remove its restrictive else-condition and let it handle
everything except the two-objects and two-arrays cases. But it
seemed to me that trying to handle both the object || array
and array || object cases in that one else-branch was poorly
thought out: only one line of code can actually be shared, and it
took several extra lines of infrastructure to support the sharing.
So I split those cases into separate else-branches.
This also addresses the inadequate documentation that was the
original complaint.
Thoughts? Should we back-patch this? The existing behavior
seems to me to be inconsistent enough to be arguably a bug,
but we've not had field complaints saying "this should work".
regards, tom lane
Commits
-
Remove "invalid concatenation of jsonb objects" error case.
- 38d30a14b05e 13.2 landed
- ff5d5611c01f 14.0 landed
- edcdbc44eed2 9.5.25 landed
- 542248f9ddfd 10.16 landed
- 1d5f3f976b26 9.6.21 landed
- 75c8ef5ae56c 11.11 landed
- 38bef9e433ef 12.6 landed