1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Add json_strip_nulls and jsonb_strip_nulls functions.

The functions remove object fields, including in nested objects, that
have null as a value. In certain cases this can lead to considerably
smaller datums, with no loss of semantic information.

Andrew Dunstan, reviewed by Pavel Stehule.
This commit is contained in:
Andrew Dunstan
2014-12-12 09:00:43 -05:00
parent b1332e98c4
commit 237a882443
11 changed files with 467 additions and 1 deletions

View File

@ -10716,6 +10716,19 @@ table2-mapping
</programlisting>
</entry>
</row>
<row>
<entry><para><literal>json_strip_nulls(from_json json)</literal>
</para><para><literal>jsonb_strip_nulls(from_json jsonb)</literal>
</para></entry>
<entry><para><type>json</type></para><para><type>jsonb</type></para></entry>
<entry>
Returns <replaceable>from_json</replaceable>
with all object fields that have null values omitted. Other null values
are untouched.
</entry>
<entry><literal>json_strip_nulls('[{"f1":1,"f2":null},2,null,3]')</literal></entry>
<entry><literal>[{"f1":1},2,null,3]</literal></entry>
</row>
</tbody>
</tgroup>
</table>
@ -10752,6 +10765,16 @@ table2-mapping
</para>
</note>
<note>
<para>
If the argument to <literal>json_strip_nulls</> contains duplicate
field names in any object, the result could be semantically somewhat
different, depending on the order in which they occur. This is not an
issue for <literal>jsonb_strip_nulls</> since jsonb values never have
duplicate object field names.
</para>
</note>
<para>
See also <xref linkend="functions-aggregate"> for the aggregate
function <function>json_agg</function> which aggregates record