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-18T17:20:33Z
Lists: pgsql-hackers
The discussion in [1] pointed out that the existing documentation
for the "jsonb || jsonb" concatenation operator is far short of
reality: it fails to acknowledge that the operator will accept
any cases other than two jsonb array inputs or two jsonb object
inputs.
I'd about concluded that other cases were handled as if by
wrapping non-array inputs in one-element arrays and then
proceeding as for two arrays. That works for most scenarios, eg
regression=# select '[3]'::jsonb || '{}'::jsonb;
?column?
----------
[3, {}]
(1 row)
regression=# select '3'::jsonb || '[]'::jsonb;
?column?
----------
[3]
(1 row)
regression=# select '3'::jsonb || '4'::jsonb;
?column?
----------
[3, 4]
(1 row)
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?
regards, tom lane
[1] https://www.postgresql.org/message-id/flat/0d72b76d-ca2b-4263-8888-d6dfca861c51%40www.fastmail.com
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