jsonb_strip_nulls with arrays?

From: Florents Tselai <florents(dot)tselai(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: jsonb_strip_nulls with arrays?
Date: 2024-09-17 09:26:36
Message-ID: 4BCECCD5-4F40-4313-9E98-9E16BEB0B01D@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Currently:

jsonb_strip_nulls ( jsonb ) → jsonb
Deletes all object fields that have null values from the given JSON value, recursively. Null values that are not object fields are untouched.

> Null values that are not object fields are untouched.

Can we revisit this and make it work with arrays, too?
Tbh, at first sight that looked like the expected behavior for me.
That is strip nulls from arrays as well.

This has been available since 9.5 and iiuc predates lots of the jsonb array work.

In practice, though, whenever jsonb_build_array is used (especially with jsonpath),
a few nulls do appear in the resulting array most of the times,
Currently, there’s no expressive way to remove this.

We could also have jsonb_array_strip_nulls(jsonb) as well

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2024-09-17 09:37:15 Re: [PATCH] Mention service key word more prominently in pg_service.conf docs
Previous Message Dagfinn Ilmari Mannsåker 2024-09-17 09:24:33 [PATCH] Mention service key word more prominently in pg_service.conf docs