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:50 -0500 |
commit | ff5d5611c01f60525c30b2c3ebc16d05edb7956d (patch) | |
tree | fdba3512f73c4805109f295ad0208846b7fb94ed /doc/src | |
parent | 86b7cca72d4d0a4e043fac0a2cdd56218ff2f258 (diff) | |
download | postgresql-ff5d5611c01f60525c30b2c3ebc16d05edb7956d.tar.gz postgresql-ff5d5611c01f60525c30b2c3ebc16d05edb7956d.zip |
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 d5cd705eebb..2707e757ca0 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -14715,8 +14715,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> @@ -14727,6 +14731,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> |