diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-12-21 13:11:29 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-12-21 13:11:51 -0500 |
commit | 38d30a14b05e0cc2996fd311d94d7ae4fe2122aa (patch) | |
tree | 3a787da72cf33fea05dd58fe9dae02e5dab359c5 /doc/src | |
parent | be9c3cd186ba86b9bc3df7ecc64b81ce4726810d (diff) |
Remove "invalid concatenation of jsonb objects" error case.
The jsonb || jsonb operator arbitrarily rejected certain combinations
of scalar and non-scalar inputs, while being willing to concatenate
other combinations. This was of course quite undocumented. Rather
than trying to document it, let's just remove the restriction,
creating a uniform rule that unless we are handling an object-to-object
concatenation, non-array inputs are converted to one-element arrays,
resulting in an array-to-array concatenation. (This does not change
the behavior for any case that didn't throw an error before.)
Per complaint from Joel Jacobson. Back-patch to all supported branches.
Discussion: https://postgr.es/m/163099.1608312033@sss.pgh.pa.us
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/func.sgml | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 8bdfade1524..06030be84c8 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -14736,8 +14736,12 @@ table2-mapping </para> <para> Concatenates two <type>jsonb</type> values. - Concatenating two objects generates an object with the union of their + Concatenating two arrays generates an array containing all the + elements of each input. Concatenating two objects generates an + object containing the union of their keys, taking the second object's value when there are duplicate keys. + All other cases are treated by converting a non-array input into a + single-element array, and then proceeding as for two arrays. Does not operate recursively: only the top-level array or object structure is merged. </para> @@ -14748,6 +14752,22 @@ table2-mapping <para> <literal>'{"a": "b"}'::jsonb || '{"c": "d"}'::jsonb</literal> <returnvalue>{"a": "b", "c": "d"}</returnvalue> + </para> + <para> + <literal>'[1, 2]'::jsonb || '3'::jsonb</literal> + <returnvalue>[1, 2, 3]</returnvalue> + </para> + <para> + <literal>'{"a": "b"}'::jsonb || '42'::jsonb</literal> + <returnvalue>[{"a": "b"}, 42]</returnvalue> + </para> + <para> + To append an array to another array as a single entry, wrap it + in an additional layer of array, for example: + </para> + <para> + <literal>'[1, 2]'::jsonb || jsonb_build_array('[3, 4]'::jsonb)</literal> + <returnvalue>[1, 2, [3, 4]]</returnvalue> </para></entry> </row> |