json (b) and null fields

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: json (b) and null fields
Date: 2014-09-26 14:59:08
Message-ID: 54257F3C.10303@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I should have been paying a bit more attention to the recent work on
adding an ignore_nulls option to row_to_json(). Here are some belated
thought. I apologize to Pavel and Stephen for not having commented earlier.

I think this is really a bandaid, and it will fail to catch lots of
cases. Several examples:

* it doesn't apply recursively, so if the row has a nested composite,
or an array of composites, none of those will have nulls ignored,
only the top level will.
* it doesn't apply to other json generators, notably json_agg().
That's a very big omission.
* it does nothing to allow us to strip nulls from existing json/jsonb
data.

I think a much more comprehensive solution would be preferable. What I
have in mind is something like

json_strip_null_fields(json) -> json

and a similar function for jsonb.

These would operate recursively. There is a downside, in that they would
be required to reprocess the json/jsonb. But adding an option like this
to all the json generator functions would be seriously ugly, especially
since they are mostly aggregate functions or variadic functions. At
least in the jsonb case the cost of reprocessing is likely to be fairly low.

cheers

andrew

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2014-09-26 15:02:16 Re: Replication identifiers, take 3
Previous Message Stephen Frost 2014-09-26 14:58:30 Re: proposal: rounding up time value less than its unit.