From c6947010ceb42143d9f047c65c1eac2b38928ab7 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Tue, 12 May 2015 15:52:45 -0400 Subject: Additional functions and operators for jsonb jsonb_pretty(jsonb) produces nicely indented json output. jsonb || jsonb concatenates two jsonb values. jsonb - text removes a key and its associated value from the json jsonb - int removes the designated array element jsonb - text[] removes a key and associated value or array element at the designated path jsonb_replace(jsonb,text[],jsonb) replaces the array element designated by the path or the value associated with the key designated by the path with the given value. Original work by Dmitry Dolgov, adapted and reworked for PostgreSQL core by Andrew Dunstan, reviewed and tidied up by Petr Jelinek. --- doc/src/sgml/func.sgml | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index bf8d72e9ff9..b1e94d7b9e2 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10293,6 +10293,32 @@ table2-mapping Do all of these key/element strings exist? '["a", "b"]'::jsonb ?& array['a', 'b'] + + || + jsonb + Concatentate two jsonb values into a new jsonb value + '["a", "b"]'::jsonb || '["c", "d"]'::jsonb + + + - + text + Delete the field with a specified key, or element with this + value + '{"a": "b"}'::jsonb - 'a' + + + - + integer + Delete the field or element with specified index (Negative + integers count from the end) + '["a", "b"]'::jsonb - 1 + + + - + text[] + Delete the field or element with specified path + '["a", {"b":1}]'::jsonb - '{1,b}'::text[] + @@ -10803,6 +10829,42 @@ table2-mapping json_strip_nulls('[{"f1":1,"f2":null},2,null,3]') [{"f1":1},2,null,3] + + jsonb_replace(target jsonb, path text[], replacement jsonb) + + jsonb + + Returns target + with the section designated by path + replaced by replacement. + + jsonb_replace('[{"f1":1,"f2":null},2,null,3]', '{0,f1}','[2,3,4]') + [{"f1":[2,3,4],"f2":null},2,null,3] + + + + jsonb_pretty(from_json jsonb) + + text + + Returns from_json + as indented json text. + + jsonb_pretty('[{"f1":1,"f2":null},2,null,3]') + + + [ + { + "f1": 1, + "f2": null + }, + 2, + null, + 3 + ] + + + -- cgit v1.2.3