X-Git-Url: https://git.8kb.co.uk/?p=postgresql%2Fpg_jsonb_opx;a=blobdiff_plain;f=README.md;fp=README.md;h=b38e3155696b74d6488ef96cb58269c83dda297c;hp=1073f68b6c8a69ae2a4a9113d573a24a8ab129d2;hb=eeec9a82f053ea71be517d39ddc4c25fccfa5579;hpb=d7958daa16351c072af5fbd5d8522f10292e1aa3 diff --git a/README.md b/README.md index 1073f68..b38e315 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,113 @@ jsonb_opx ========= -Test delete and concatenation operators for PostgreSQL 9.4 +Test delete and concatenation operators for PostgreSQL 9.4, this is purely for experimentation and contain errors and bad form. -This is purely experimentation and will contain many errors and bad form. +**USE ON PRODUCTION SYSTEMS AT OWN RISK** -**DO NOT USE ON PRODUCTION SYSTEMS** +* delete operator **"-"** provided by functions *jsonb_delete(jsonb, text) jsonb_delete(jsonb, text[]) and jsonb_delete(jsonb, jsonb)* + Provides: + jsonb - text + jsonb - text[] + jsonb - jsonb + Note: When using text type operators on jsonb arrays only elements of type text will be deleted. E.g. + +```sql +TEST=# SELECT '[1, "1", "2", 2]'::jsonb - '2'::text; + ?column? +------------- + [1, "1", 2] +(1 row) + +TEST=# SELECT '[1, "1", "2", 2]'::jsonb - '"2"'::text; + ?column? +------------------ + [1, "1", "2", 2] +(1 row) + +TEST=# SELECT '[1, "1", "2", 2]'::jsonb - array['2']::text[]; + ?column? +------------- + [1, "1", 2] +(1 row) + +TEST=# SELECT '[1, "1", "2", 2]'::jsonb - array['"2"']::text[]; + ?column? +------------------ + [1, "1", "2", 2] +(1 row) + +``` + + More. E.g. + +```sql +TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - 'b'::text; + ?column? +------------------ + {"a": 1, "c": 3} +(1 row) + +TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['a','b']; + ?column? +---------- + {"c": 3} +(1 row) + +TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - '{"a": 4, "b": 2}'::jsonb; + ?column? +------------------ + {"a": 1, "c": 3} +(1 row) + +TEST=# SELECT '{"a": 1, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"d": {"a": 4}, "b": 2}'::jsonb; + ?column? +------------------ + {"a": 1, "c": 3} +(1 row) + +TEST=# SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"a": 4, "b": 2}'::jsonb; + ?column? +------------------------- + {"c": 3, "d": {"a": 4}} +(1 row) +``` + +* concatenation operator **"||"** provided by function *jsonb_concat(jsonb, jsonb)* + Provides: + jsonb || jsonb + + E.g. + +```sql +TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '{"a": 4, "b": 2, "d": 4}'::jsonb; + ?column? +---------------------------------- + {"a": 4, "b": 2, "c": 3, "d": 4} +(1 row) + +TEST=# SELECT '["a", "b"]'::jsonb || '["c"]'::jsonb; + ?column? +----------------- + ["a", "b", "c"] +(1 row) + +TEST=# SELECT '[1,2,3]'::jsonb || '[3,4,5]'::jsonb; + ?column? +-------------------- + [1, 2, 3, 3, 4, 5] +(1 row) + +TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '[1,2,3]'::jsonb; + ?column? +------------------------------------- + [{"a": 1, "b": 2, "c": 3}, 1, 2, 3] +(1 row) + +TEST=# SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '[1,2,3]'::jsonb || '"a"'::jsonb; + ?column? +------------------------------------------ + [{"a": 1, "b": 2, "c": 3}, 1, 2, 3, "a"] +(1 row) +```