mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
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
This commit is contained in:
@ -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>
|
||||
|
||||
|
Reference in New Issue
Block a user