]> git.8kb.co.uk Git - postgresql/pg_jsonb_opx/blob - sql/jsonb_opx.sql
Add subdirectories for regression checks
[postgresql/pg_jsonb_opx] / sql / jsonb_opx.sql
1 \i /usr/local/pgsql/share/contrib/jsonb_opx.sql
2
3 -------------------------------------------------------------------------------
4 -- Tests for jsonb - text
5 -------------------------------------------------------------------------------
6
7 -- text deletion from array containers will only delete string types as only strings can be keys:
8 SELECT '[1, "1", "2", 2]'::jsonb - '2'::text;
9
10 -- simple text deletion from an object container
11 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - 'b'::text;
12
13 -- simple text deletion from an object container should only match keys
14 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - '3'::text;
15
16 -- others
17 SELECT '["1", "2", true, false]'::jsonb - '2'::text;
18 SELECT '["1", "2", "2", "2"]'::jsonb - '2'::text;
19
20 -------------------------------------------------------------------------------
21 -- Tests for jsonb - text[]
22 -------------------------------------------------------------------------------
23
24 -- text[] deletion from array containers will only delete string types as only strings can be keys:
25 SELECT '[1, "1", "2", 2]'::jsonb - array['1','2'];
26
27 -- simple text[] deletion from an object container
28 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['a',' b'];
29
30 -- simple text[] deletion from an object container should only match keys
31 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['1',' 2'];
32
33 -------------------------------------------------------------------------------
34 -- Tests for jsonb - jsonb
35 -------------------------------------------------------------------------------
36
37 -- jsonb deletion from an object should match on key/value
38 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - '{"a": 4, "b": 2}'::jsonb;
39
40 -- jsonb deletion from an array should only match on key
41 SELECT '["a", "b", "c"]'::jsonb - '{"a": 4, "b": 2}'::jsonb;
42
43 -- jsonb deletion from nested objectys should not be part matched
44 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"a": 4, "b": 2}'::jsonb
45
46 -- but a match of all nested values should narcg
47 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"d": {"a": 4}, "b": 2}'::jsonb
48
49 -- others
50 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": false}}'::jsonb - '{"d": {"a": false}, "b": 2}'::jsonb
51
52 -------------------------------------------------------------------------------
53 -- Tests for jsonb || jsonb
54 -------------------------------------------------------------------------------
55
56 -- duplicates should automatically be removed by lower level logic
57 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '{"a": 4, "b": 2, "d": 4}'::jsonb;
58
59 -- concatentation of arrays
60 SELECT '["a", "b"]'::jsonb || '["c"]'::jsonb;
61
62 -- concatentation of scalars and arrays should be wrapped into arrays
63 SELECT '["a", "b"]'::jsonb || '"c"'::jsonb;
64
65 -- likewise concatentation of objects and arrays should be wrapped into arrays
66 SELECT '["a", "b"]'::jsonb || '{"a": 4, "b": 2}'::jsonb;
67
68 -- and all concatentation should be in natural order supplied
69 SELECT '{"a": 4, "b": 2}'::jsonb || '["a", "b"]'::jsonb || '["c", "d"]'::jsonb;
70
71 -- others
72 SELECT 'false'::jsonb || '["a", "b"]'::jsonb || '["c", "d"]'::jsonb;