4 Test delete and concatenation operators for PostgreSQL 9.4, this is purely for experimentation and contain errors and bad form.
6 **USE ON PRODUCTION SYSTEMS AT OWN RISK**
8 * delete operator **"-"** provided by functions *jsonb_delete(jsonb, text) jsonb_delete(jsonb, text[]) and jsonb_delete(jsonb, jsonb)*
14 Note: When using text type operators on jsonb arrays only elements of type text will be deleted. E.g.
17 TEST=# SELECT '[1, "1", "2", 2]'::jsonb - '2'::text;
23 TEST=# SELECT '[1, "1", "2", 2]'::jsonb - '"2"'::text;
29 TEST=# SELECT '[1, "1", "2", 2]'::jsonb - array['2']::text[];
35 TEST=# SELECT '[1, "1", "2", 2]'::jsonb - array['"2"']::text[];
46 TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - 'b'::text;
52 TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['a','b'];
58 TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - '{"a": 4, "b": 2}'::jsonb;
64 TEST=# SELECT '{"a": 1, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"d": {"a": 4}, "b": 2}'::jsonb;
70 TEST=# SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"a": 4, "b": 2}'::jsonb;
72 -------------------------
73 {"c": 3, "d": {"a": 4}}
77 * concatenation operator **"||"** provided by function *jsonb_concat(jsonb, jsonb)*
84 TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '{"a": 4, "b": 2, "d": 4}'::jsonb;
86 ----------------------------------
87 {"a": 4, "b": 2, "c": 3, "d": 4}
90 TEST=# SELECT '["a", "b"]'::jsonb || '["c"]'::jsonb;
96 TEST=# SELECT '[1,2,3]'::jsonb || '[3,4,5]'::jsonb;
102 TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '[1,2,3]'::jsonb;
104 -------------------------------------
105 [{"a": 1, "b": 2, "c": 3}, 1, 2, 3]
108 TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '[1,2,3]'::jsonb || '"a"'::jsonb;
110 ------------------------------------------
111 [{"a": 1, "b": 2, "c": 3}, 1, 2, 3, "a"]