diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2016-04-06 19:20:17 +0300 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2016-04-06 19:25:00 +0300 |
commit | 0b62fd036e1ac48a8432bb9664b21e1f036c1b08 (patch) | |
tree | 09a2b9176bb6b7ed77b86af1c212e7e2a18678a5 /doc/src | |
parent | 3b3fcc4eeaeecff315420833975e7c87d760bfe1 (diff) |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/func.sgml | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index f60d5784fdd..2ce89bb030f 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10903,6 +10903,9 @@ table2-mapping <primary>jsonb_set</primary> </indexterm> <indexterm> + <primary>jsonb_insert</primary> + </indexterm> + <indexterm> <primary>jsonb_pretty</primary> </indexterm> @@ -11184,6 +11187,39 @@ table2-mapping </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> <entry><para><type>text</type></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 |