mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Add jsonb_insert
It inserts a new value into an jsonb array at arbitrary position or a new key to jsonb object. Author: Dmitry Dolgov Reviewers: Petr Jelinek, Vitaly Burovoy, Andrew Dunstan
This commit is contained in:
@ -10902,6 +10902,9 @@ table2-mapping
|
||||
<indexterm>
|
||||
<primary>jsonb_set</primary>
|
||||
</indexterm>
|
||||
<indexterm>
|
||||
<primary>jsonb_insert</primary>
|
||||
</indexterm>
|
||||
<indexterm>
|
||||
<primary>jsonb_pretty</primary>
|
||||
</indexterm>
|
||||
@ -11183,6 +11186,39 @@ table2-mapping
|
||||
</para><para><literal>[{"f1": 1, "f2": null, "f3": [2, 3, 4]}, 2]</literal>
|
||||
</para></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
<para><literal>
|
||||
jsonb_insert(target jsonb, path text[], new_value jsonb, <optional><parameter>insert_after</parameter> <type>boolean</type></optional>)
|
||||
</literal></para>
|
||||
</entry>
|
||||
<entry><para><type>jsonb</type></para></entry>
|
||||
<entry>
|
||||
Returns <replaceable>target</replaceable> with
|
||||
<replaceable>new_value</replaceable> inserted. If
|
||||
<replaceable>target</replaceable> section designated by
|
||||
<replaceable>path</replaceable> is in a JSONB array,
|
||||
<replaceable>new_value</replaceable> will be inserted before target or
|
||||
after if <replaceable>insert_after</replaceable> is true (default is
|
||||
<literal>false</>). If <replaceable>target</replaceable> section
|
||||
designated by <replaceable>path</replaceable> is in JSONB object,
|
||||
<replaceable>new_value</replaceable> will be inserted only if
|
||||
<replaceable>target</replaceable> does not exist. As with the path
|
||||
orientated operators, negative integers that appear in
|
||||
<replaceable>path</replaceable> count from the end of JSON arrays.
|
||||
</entry>
|
||||
<entry>
|
||||
<para><literal>
|
||||
jsonb_insert('{"a": [0,1,2]}', '{a, 1}', '"new_value"')
|
||||
</literal></para>
|
||||
<para><literal>
|
||||
jsonb_insert('{"a": [0,1,2]}', '{a, 1}', '"new_value"', true)
|
||||
</literal></para>
|
||||
</entry>
|
||||
<entry><para><literal>{"a": [0, "new_value", 1, 2]}</literal>
|
||||
</para><para><literal>{"a": [0, 1, "new_value", 2]}</literal>
|
||||
</para></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><para><literal>jsonb_pretty(from_json jsonb)</literal>
|
||||
</para></entry>
|
||||
@ -11235,10 +11271,11 @@ table2-mapping
|
||||
<note>
|
||||
<para>
|
||||
All the items of the <literal>path</> parameter of <literal>jsonb_set</>
|
||||
must be present in the <literal>target</>, unless
|
||||
<literal>create_missing</> is true, in which case all but the last item
|
||||
must be present. If these conditions are not met the <literal>target</>
|
||||
is returned unchanged.
|
||||
as well as <literal>jsonb_insert</> except the last item must be present
|
||||
in the <literal>target</>. If <literal>create_missing</> is false, all
|
||||
items of the <literal>path</> parameter of <literal>jsonb_set</> must be
|
||||
present. If these conditions are not met the <literal>target</> is
|
||||
returned unchanged.
|
||||
</para>
|
||||
<para>
|
||||
If the last path item is an object key, it will be created if it
|
||||
|
Reference in New Issue
Block a user