@@ -10323,6 +10323,15 @@ table2-mapping
10323
10323
</tgroup>
10324
10324
</table>
10325
10325
10326
+ <note>
10327
+ <para>
10328
+ The <literal>||</> operator concatenates the elements at the top level of
10329
+ each of its operands. It does not operate recursively. For example, if
10330
+ both operands are objects with a common key field name, the value of the
10331
+ field in the result will just be the value from the right hand operand.
10332
+ </para>
10333
+ </note>
10334
+
10326
10335
<para>
10327
10336
<xref linkend="functions-json-creation-table"> shows the functions that are
10328
10337
available for creating <type>json</type> and <type>jsonb</type> values.
@@ -10830,17 +10839,24 @@ table2-mapping
10830
10839
<entry><literal>[{"f1":1},2,null,3]</literal></entry>
10831
10840
</row>
10832
10841
<row>
10833
- <entry><para><literal>jsonb_replace (target jsonb, path text[], replacement jsonb)</literal>
10842
+ <entry><para><literal>jsonb_set (target jsonb, path text[], new_value jsonb<optional>, <parameter>create_missing</parameter> <type>boolean</type></optional> )</literal>
10834
10843
</para></entry>
10835
10844
<entry><para><type>jsonb</type></para></entry>
10836
10845
<entry>
10837
10846
Returns <replaceable>target</replaceable>
10838
- with the section designated by <replaceable>path</replaceable>
10839
- replaced by <replaceable>replacement</replaceable>.
10840
- </entry>
10841
- <entry><literal>jsonb_replace('[{"f1":1,"f2":null},2,null,3]', '{0,f1}','[2,3,4]')</literal></entry>
10842
- <entry><literal>[{"f1":[2,3,4],"f2":null},2,null,3]</literal>
10843
- </entry>
10847
+ with the section designated by <replaceable>path</replaceable>
10848
+ replaced by <replaceable>new_value</replaceable>, or with
10849
+ <replaceable>new_value</replaceable> added if
10850
+ <replaceable>create_missing</replaceable> is true ( default is
10851
+ <literal>true</>) and the item
10852
+ designated by <replaceable>path</replaceable> does not exist.
10853
+ </entry>
10854
+ <entry><para><literal>jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0,f1}','[2,3,4]', false)</literal>
10855
+ </para><para><literal>jsonb_set('[{"f1":1,"f2":null},2]', '{0,f3}','[2,3,4]')</literal>
10856
+ </para></entry>
10857
+ <entry><para><literal>[{"f1":[2,3,4],"f2":null},2,null,3]</literal>
10858
+ </para><para><literal>[{"f1": 1, "f2": null, "f3": [2, 3, 4]}, 2]</literal>
10859
+ </para></entry>
10844
10860
</row>
10845
10861
<row>
10846
10862
<entry><para><literal>jsonb_pretty(from_json jsonb)</literal>
@@ -10891,6 +10907,27 @@ table2-mapping
10891
10907
</para>
10892
10908
</note>
10893
10909
10910
+ <note>
10911
+ <para>
10912
+ All the items of the <literal>path</> parameter of <literal>jsonb_set</>
10913
+ must be present in the <literal>target</>, unless
10914
+ <literal>create_missing</> is true, in which case all but the last item
10915
+ must be present. If these conditions are not met the <literal>target</>
10916
+ is returned unchanged.
10917
+ </para>
10918
+ <para>
10919
+ If the last path item is an object key, it will be created if it
10920
+ is absent and given the new value. If the last path item is an array
10921
+ index, if it is positive the item to set is found by counting from
10922
+ the left, and if negative by counting from the right - <literal>-1</>
10923
+ designates the rightmost element, and so on.
10924
+ If the item is out of the range -array_length .. array_length -1,
10925
+ and create_missing is true, the new value is added at the beginning
10926
+ of the array if the item is negative, and at the end of the array if
10927
+ it is positive.
10928
+ </para>
10929
+ </note>
10930
+
10894
10931
<note>
10895
10932
<para>
10896
10933
The <literal>json_typeof</> function's <literal>null</> return value
0 commit comments