]> git.8kb.co.uk Git - postgresql/jsonb_delete/blob - expected/jsonb_delete.out
Initial commit
[postgresql/jsonb_delete] / expected / jsonb_delete.out
1 CREATE EXTENSION jsonb_delete VERSION '1.0';
2 -- jsonb deletion from an object should match on key/value
3 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - '{"a": 4, "b": 2}'::jsonb;
4      ?column?     
5 ------------------
6  {"a": 1, "c": 3}
7 (1 row)
8
9 -- jsonb deletion from an array should only match on element
10 SELECT '["a", "b", "c"]'::jsonb - '{"a": 4, "b": 2}'::jsonb;
11     ?column?     
12 -----------------
13  ["a", "b", "c"]
14 (1 row)
15
16 -- jsonb deletion from nested objects should not be part matched
17 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"a": 4, "b": 2}'::jsonb;
18         ?column?         
19 -------------------------
20  {"c": 3, "d": {"a": 4}}
21 (1 row)
22
23 -- but a match of all nested values should
24 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"d": {"a": 4}, "b": 2}'::jsonb;
25      ?column?     
26 ------------------
27  {"a": 4, "c": 3}
28 (1 row)
29
30 SELECT '{"a":{"b":{"c":[1,[2,3,[4]],{"d":1}]}, "c":[1,2,3,4]}, "d":2}'::jsonb - '{"d":2}'::jsonb;
31                               ?column?                              
32 --------------------------------------------------------------------
33  {"a": {"b": {"c": [1, [2, 3, [4]], {"d": 1}]}, "c": [1, 2, 3, 4]}}
34 (1 row)
35
36 -- jsonb nulls are equal
37 SELECT '{"a": 1, "b": 2, "c": null}'::jsonb - '{"a": 4, "c": null}'::jsonb;
38      ?column?     
39 ------------------
40  {"a": 1, "b": 2}
41 (1 row)
42
43 -- others
44 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": false}}'::jsonb - '{"d": {"a": false}, "b": 2}'::jsonb;
45      ?column?     
46 ------------------
47  {"a": 4, "c": 3}
48 (1 row)
49
50 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}}'::jsonb - '{"a": "test2", "c": {"a": false}, "b": 2.2}'::jsonb;
51    ?column?    
52 ---------------
53  {"a": "test"}
54 (1 row)
55
56 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test2", "b": 2.3, "c": {"a": true}, "d":false, "e":[1,2,3]}'::jsonb;
57                                 ?column?                                 
58 -------------------------------------------------------------------------
59  {"a": "test", "b": 2.2, "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
60 (1 row)
61
62 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test", "b": 2.3, "c": {"a": true}, "d":false, "e":[1,2,3]}'::jsonb;
63                           ?column?                          
64 ------------------------------------------------------------
65  {"b": 2.2, "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
66 (1 row)
67
68 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test2", "b": 2.2, "c": {"a": true}, "d":false, "e":[1,2,3]}'::jsonb;
69                            ?column?                            
70 ---------------------------------------------------------------
71  {"a": "test", "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
72 (1 row)
73
74 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test2", "b": 2.3, "c": {"a": false}, "d":false, "e":[1,2,3]}'::jsonb;
75                        ?column?                       
76 ------------------------------------------------------
77  {"a": "test", "b": 2.2, "d": true, "e": [1, 2, "a"]}
78 (1 row)
79
80 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test2", "b": 2.3, "c": {"a": true}, "d":true, "e":[1,2,3]}'::jsonb;
81                            ?column?                           
82 --------------------------------------------------------------
83  {"a": "test", "b": 2.2, "c": {"a": false}, "e": [1, 2, "a"]}
84 (1 row)
85
86 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test2", "b": 2.3, "c": {"a": true}, "d":false, "e":[1,"a",2]}'::jsonb;
87                                 ?column?                                 
88 -------------------------------------------------------------------------
89  {"a": "test", "b": 2.2, "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
90 (1 row)
91
92 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test2", "b": 2.3, "c": {"a": true}, "d":false, "e":[1,2,"a"]}'::jsonb;
93                        ?column?                        
94 -------------------------------------------------------
95  {"a": "test", "b": 2.2, "c": {"a": false}, "d": true}
96 (1 row)
97
98 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test", "b": 2.2, "c": {"a": true}, "d":false, "e":[1,2,3]}'::jsonb;
99                      ?column?                     
100 --------------------------------------------------
101  {"c": {"a": false}, "d": true, "e": [1, 2, "a"]}
102 (1 row)
103
104 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test", "b": 2.2, "c": {"a": false}, "d":false, "e":[1,2,3]}'::jsonb;
105            ?column?            
106 -------------------------------
107  {"d": true, "e": [1, 2, "a"]}
108 (1 row)
109
110 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,3]}'::jsonb;
111       ?column?      
112 --------------------
113  {"e": [1, 2, "a"]}
114 (1 row)
115
116 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb - '{"a": "test", "b": 2.2, "c": {"a": false}, "d":true, "e":[1,2,"a"]}'::jsonb;
117  ?column? 
118 ----------
119  {}
120 (1 row)
121
122 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '[[1]]'::jsonb;
123           ?column?          
124 ----------------------------
125  ["a", 2, {"a": 1, "b": 2}]
126 (1 row)
127
128 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '[{"a":1}]'::jsonb;
129           ?column?          
130 ----------------------------
131  ["a", 2, {"a": 1, "b": 2}]
132 (1 row)
133
134 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '[{"a":1, "b":2}]'::jsonb;
135  ?column? 
136 ----------
137  ["a", 2]
138 (1 row)
139
140 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '["a"]'::jsonb;
141        ?column?        
142 -----------------------
143  [2, {"a": 1, "b": 2}]
144 (1 row)
145
146 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '[2]'::jsonb;
147         ?column?         
148 -------------------------
149  ["a", {"a": 1, "b": 2}]
150 (1 row)
151