1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

Add a non-strict version of jsonb_set

jsonb_set_lax() is the same as jsonb_set, except that it takes and extra
argument that specifies what to do if the value argument is NULL. The
default is 'use_json_null'. Other possibilities are 'raise_exception',
'return_target' and 'delete_key', all these behaviours having been
suggested as reasonable by various users.

Discussion: https://postgr.es/m/375873e2-c957-3a8d-64f9-26c43c2b16e7@2ndQuadrant.com

Reviewed by: Pavel Stehule
This commit is contained in:
Andrew Dunstan
2020-01-17 11:41:35 +10:30
parent f7cd5896a6
commit a83586b554
6 changed files with 176 additions and 0 deletions

View File

@@ -12231,6 +12231,9 @@ table2-mapping
<indexterm>
<primary>jsonb_set</primary>
</indexterm>
<indexterm>
<primary>jsonb_set_lax</primary>
</indexterm>
<indexterm>
<primary>jsonb_insert</primary>
</indexterm>
@@ -12545,6 +12548,26 @@ table2-mapping
</para><para><literal>[{"f1": 1, "f2": null, "f3": [2, 3, 4]}, 2]</literal>
</para></entry>
</row>
<row>
<entry><para><literal>jsonb_set_lax(target jsonb, path text[], new_value jsonb <optional>, create_missing boolean</optional> <optional>, null_value_treatment text</optional>)</literal>
</para></entry>
<entry><para><type>jsonb</type></para></entry>
<entry>
If <replaceable>new_value</replaceable> is not <literal>null</literal>,
behaves identically to <literal>jsonb_set</literal>. Otherwise behaves
according to the value of <replaceable>null_value_treatment</replaceable>
which must be one of <literal>'raise_exception'</literal>,
<literal>'use_json_null'</literal>, <literal>'delete_key'</literal>, or
<literal>'return_target'</literal>. The default is
<literal>'use_json_null'</literal>.
</entry>
<entry><para><literal>jsonb_set_lax('[{"f1":1,"f2":null},2,null,3]', '{0,f1}',null)</literal>
</para><para><literal>jsonb_set_lax('[{"f1":99,"f2":null},2]', '{0,f3}',null, true, 'return_target')</literal>
</para></entry>
<entry><para><literal>[{"f1":null,"f2":null},2,null,3]</literal>
</para><para><literal>[{"f1": 99, "f2": null}, 2]</literal>
</para></entry>
</row>
<row>
<entry>
<para><literal>