mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Allow json{b}_strip_nulls to remove null array elements
An additional paramater ("strip_in_arrays") is added to these functions. It defaults to false. If true, then null array elements are removed as well as null valued object fields. JSON that just consists of a single null is not affected. Author: Florents Tselai <florents.tselai@gmail.com> Discussion: https://postgr.es/m/4BCECCD5-4F40-4313-9E98-9E16BEB0B01D@gmail.com
This commit is contained in:
@@ -17345,25 +17345,32 @@ ERROR: value too long for type character(2)
|
||||
<indexterm>
|
||||
<primary>json_strip_nulls</primary>
|
||||
</indexterm>
|
||||
<function>json_strip_nulls</function> ( <type>json</type> )
|
||||
<function>json_strip_nulls</function> ( <parameter>target</parameter> <type>jsonb</type>, <optional>,<parameter>strip_in_arrays</parameter> <type>boolean</type> </optional> )
|
||||
<returnvalue>json</returnvalue>
|
||||
</para>
|
||||
<para role="func_signature">
|
||||
<indexterm>
|
||||
<primary>jsonb_strip_nulls</primary>
|
||||
</indexterm>
|
||||
<function>jsonb_strip_nulls</function> ( <type>jsonb</type> )
|
||||
<function>jsonb_strip_nulls</function> ( <parameter>target</parameter> <type>jsonb</type>, <optional>,<parameter>strip_in_arrays</parameter> <type>boolean</type> </optional> )
|
||||
<returnvalue>jsonb</returnvalue>
|
||||
</para>
|
||||
<para>
|
||||
Deletes all object fields that have null values from the given JSON
|
||||
value, recursively. Null values that are not object fields are
|
||||
untouched.
|
||||
value, recursively.
|
||||
If <parameter>strip_in_arrays</parameter> is true (the default is false),
|
||||
null array elements are also stripped.
|
||||
Otherwise they are not stripped. Bare null values are never stripped.
|
||||
</para>
|
||||
<para>
|
||||
<literal>json_strip_nulls('[{"f1":1, "f2":null}, 2, null, 3]')</literal>
|
||||
<returnvalue>[{"f1":1},2,null,3]</returnvalue>
|
||||
</para></entry>
|
||||
</para>
|
||||
<para>
|
||||
<literal>jsonb_strip_nulls('[1,2,null,3,4]', true);</literal>
|
||||
<returnvalue>[1,2,3,4]</returnvalue>
|
||||
</para>
|
||||
</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
|
Reference in New Issue
Block a user