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



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to