mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +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:
@ -509,3 +509,23 @@ select * from json_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","
|
||||
|
||||
select * from json_to_recordset('[{"a":1,"b":{"d":"foo"},"c":true},{"a":2,"c":false,"b":{"d":"bar"}}]')
|
||||
as x(a int, b json, c boolean);
|
||||
|
||||
|
||||
-- json_strip_nulls
|
||||
|
||||
select json_strip_nulls(null);
|
||||
|
||||
select json_strip_nulls('1');
|
||||
|
||||
select json_strip_nulls('"a string"');
|
||||
|
||||
select json_strip_nulls('null');
|
||||
|
||||
select json_strip_nulls('[1,2,null,3,4]');
|
||||
|
||||
select json_strip_nulls('{"a":1,"b":null,"c":[2,null,3],"d":{"e":4,"f":null}}');
|
||||
|
||||
select json_strip_nulls('[1,{"a":1,"b":null,"c":2},3]');
|
||||
|
||||
-- an empty object is not null and should not be stripped
|
||||
select json_strip_nulls('{"a": {"b": null, "c": null}, "d": {} }');
|
||||
|
Reference in New Issue
Block a user