diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2014-12-12 09:00:43 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2014-12-12 09:00:43 -0500 |
commit | 237a8824430c607fce1eafde0c625744d50a455c (patch) | |
tree | e8f0fcf9806697ef2754e83b24815a2c97af363d /src/test/regress/sql/json.sql | |
parent | b1332e98c441b40300670f55a4303bf69cd8b226 (diff) | |
download | postgresql-237a8824430c607fce1eafde0c625744d50a455c.tar.gz postgresql-237a8824430c607fce1eafde0c625744d50a455c.zip |
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.
Diffstat (limited to 'src/test/regress/sql/json.sql')
-rw-r--r-- | src/test/regress/sql/json.sql | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/regress/sql/json.sql b/src/test/regress/sql/json.sql index c9801321e09..36a6674ff91 100644 --- a/src/test/regress/sql/json.sql +++ b/src/test/regress/sql/json.sql @@ -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": {} }'); |