]> git.8kb.co.uk Git - postgresql/pg_jsonb_opx/blob - expected/jsonb_opx.out
Had a play at making the following changes today, some will be a bit ugly as just...
[postgresql/pg_jsonb_opx] / expected / jsonb_opx.out
1 CREATE EXTENSION jsonb_opx;
2 -------------------------------------------------------------------------------
3 -- Tests for jsonb - text
4 -------------------------------------------------------------------------------
5 -- text deletion from array containers will only delete string types as only strings can be keys:
6 SELECT '[1, "1", "2", 2]'::jsonb - '2'::text;
7   ?column?   
8 -------------
9  [1, "1", 2]
10 (1 row)
11
12 -- simple text deletion from an object container
13 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - 'b'::text;
14      ?column?     
15 ------------------
16  {"a": 1, "c": 3}
17 (1 row)
18
19 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - 'b '::text;
20          ?column?         
21 --------------------------
22  {"a": 1, "b": 2, "c": 3}
23 (1 row)
24
25 SELECT '{"a": 1, "b": 2, "c": {"b": 3}}'::jsonb - 'b'::text;
26         ?column?         
27 -------------------------
28  {"a": 1, "c": {"b": 3}}
29 (1 row)
30
31 SELECT '{"a": 1, "b": 2, "c": {"b": [1,2,3]}}'::jsonb - 'b'::text;
32             ?column?             
33 ---------------------------------
34  {"a": 1, "c": {"b": [1, 2, 3]}}
35 (1 row)
36
37 SELECT '{"a": 1, "b": 2, "c":[1,2,3]}'::jsonb - 'b'::text;
38          ?column?         
39 --------------------------
40  {"a": 1, "c": [1, 2, 3]}
41 (1 row)
42
43 SELECT '{"a": 1, "b": 2, "c":[1,2,3]}'::jsonb - 'c'::text;
44      ?column?     
45 ------------------
46  {"a": 1, "b": 2}
47 (1 row)
48
49 -- simple text deletion from an object container should only match keys
50 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - '3'::text;
51          ?column?         
52 --------------------------
53  {"a": 1, "b": 2, "c": 3}
54 (1 row)
55
56 -- others
57 SELECT '["1", "2", true, false]'::jsonb - '2'::text;
58       ?column?      
59 --------------------
60  ["1", true, false]
61 (1 row)
62
63 SELECT '["1", "2", "2", "2"]'::jsonb - '2'::text;
64  ?column? 
65 ----------
66  ["1"]
67 (1 row)
68
69 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - 'a'::text;
70        ?column?        
71 -----------------------
72  [2, {"a": 1, "b": 2}]
73 (1 row)
74
75 SELECT '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb - 'a'::text;
76  ?column? 
77 ----------
78  {"d": 2}
79 (1 row)
80
81 SELECT '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb - 'd'::text;
82               ?column?              
83 ------------------------------------
84  {"a": {"b": 3, "c": [1, 2, 3, 4]}}
85 (1 row)
86
87 SELECT '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb - 'b'::text;
88                   ?column?                  
89 --------------------------------------------
90  {"a": {"b": 3, "c": [1, 2, 3, 4]}, "d": 2}
91 (1 row)
92
93 -------------------------------------------------------------------------------
94 -- Tests for jsonb - text[]
95 -------------------------------------------------------------------------------
96 -- text[] deletion from array containers will only delete string types as only strings can be keys:
97 SELECT '[1, "1", "2", 2]'::jsonb - array['1','2'];
98  ?column? 
99 ----------
100  [1, 2]
101 (1 row)
102
103 -- simple text[] deletion from an object container
104 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['a','b'];
105  ?column? 
106 ----------
107  {"c": 3}
108 (1 row)
109
110 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['a ','b ',' c'];
111          ?column?         
112 --------------------------
113  {"a": 1, "b": 2, "c": 3}
114 (1 row)
115
116 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['a','b','c'];
117  ?column? 
118 ----------
119  {}
120 (1 row)
121
122 SELECT '{"a": 1, "b": 2, "c": {"b": 3}}'::jsonb - ARRAY['a','b']; 
123     ?column?     
124 -----------------
125  {"c": {"b": 3}}
126 (1 row)
127
128 SELECT '{"a": 1, "b": 2, "c": {"b": [1,2,3]}}'::jsonb - ARRAY['a','b'];
129         ?column?         
130 -------------------------
131  {"c": {"b": [1, 2, 3]}}
132 (1 row)
133
134 SELECT '{"a": 1, "b": 2, "c":[1,2,3]}'::jsonb - ARRAY['a','b'];
135      ?column?     
136 ------------------
137  {"c": [1, 2, 3]}
138 (1 row)
139
140 SELECT '{"a": 1, "b": 2, "c":[1,2,3]}'::jsonb - ARRAY['a','c'];
141  ?column? 
142 ----------
143  {"b": 2}
144 (1 row)
145
146 SELECT '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb - ARRAY['b','d'];
147               ?column?              
148 ------------------------------------
149  {"a": {"b": 3, "c": [1, 2, 3, 4]}}
150 (1 row)
151
152 SELECT '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb - ARRAY['b','a'];
153  ?column? 
154 ----------
155  {"d": 2}
156 (1 row)
157
158 SELECT '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb - ARRAY['a','d'];
159  ?column? 
160 ----------
161  {}
162 (1 row)
163
164 -- simple text[] deletion from an object container should only match keys or nulls
165 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - ARRAY['1',' 2'];
166          ?column?         
167 --------------------------
168  {"a": 1, "b": 2, "c": 3}
169 (1 row)
170
171 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '{a}'::text[];
172        ?column?        
173 -----------------------
174  [2, {"a": 1, "b": 2}]
175 (1 row)
176
177 SELECT '["1",2]'::jsonb - ARRAY[null];
178  ?column? 
179 ----------
180  ["1", 2]
181 (1 row)
182
183 SELECT '["1",null,2]'::jsonb - ARRAY[null];
184  ?column? 
185 ----------
186  ["1", 2]
187 (1 row)
188
189 -------------------------------------------------------------------------------
190 -- Tests for jsonb - jsonb
191 -------------------------------------------------------------------------------
192 -- jsonb deletion from an object should match on key/value
193 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb - '{"a": 4, "b": 2}'::jsonb;
194      ?column?     
195 ------------------
196  {"a": 1, "c": 3}
197 (1 row)
198
199 -- jsonb deletion from an array should only match on key
200 SELECT '["a", "b", "c"]'::jsonb - '{"a": 4, "b": 2}'::jsonb;
201  ?column? 
202 ----------
203  ["c"]
204 (1 row)
205
206 -- jsonb deletion from nested objects should not be part matched
207 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"a": 4, "b": 2}'::jsonb;
208         ?column?         
209 -------------------------
210  {"c": 3, "d": {"a": 4}}
211 (1 row)
212
213 -- but a match of all nested values should narcg
214 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": 4}}'::jsonb - '{"d": {"a": 4}, "b": 2}'::jsonb;
215      ?column?     
216 ------------------
217  {"a": 4, "c": 3}
218 (1 row)
219
220 -- others
221 SELECT '{"a": 4, "b": 2, "c": 3, "d": {"a": false}}'::jsonb - '{"d": {"a": false}, "b": 2}'::jsonb;
222      ?column?     
223 ------------------
224  {"a": 4, "c": 3}
225 (1 row)
226
227 SELECT '{"a": "test", "b": 2.2, "c": {"a": false}}'::jsonb - '{"a": "test2", "c": {"a": false}, "b": 2.2}'::jsonb;
228    ?column?    
229 ---------------
230  {"a": "test"}
231 (1 row)
232
233 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;
234                                 ?column?                                 
235 -------------------------------------------------------------------------
236  {"a": "test", "b": 2.2, "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
237 (1 row)
238
239 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;
240                           ?column?                          
241 ------------------------------------------------------------
242  {"b": 2.2, "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
243 (1 row)
244
245 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;
246                            ?column?                            
247 ---------------------------------------------------------------
248  {"a": "test", "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
249 (1 row)
250
251 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;
252                        ?column?                       
253 ------------------------------------------------------
254  {"a": "test", "b": 2.2, "d": true, "e": [1, 2, "a"]}
255 (1 row)
256
257 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;
258                            ?column?                           
259 --------------------------------------------------------------
260  {"a": "test", "b": 2.2, "c": {"a": false}, "e": [1, 2, "a"]}
261 (1 row)
262
263 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;
264                                 ?column?                                 
265 -------------------------------------------------------------------------
266  {"a": "test", "b": 2.2, "c": {"a": false}, "d": true, "e": [1, 2, "a"]}
267 (1 row)
268
269 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;
270                        ?column?                        
271 -------------------------------------------------------
272  {"a": "test", "b": 2.2, "c": {"a": false}, "d": true}
273 (1 row)
274
275 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;
276                      ?column?                     
277 --------------------------------------------------
278  {"c": {"a": false}, "d": true, "e": [1, 2, "a"]}
279 (1 row)
280
281 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;
282            ?column?            
283 -------------------------------
284  {"d": true, "e": [1, 2, "a"]}
285 (1 row)
286
287 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;
288       ?column?      
289 --------------------
290  {"e": [1, 2, "a"]}
291 (1 row)
292
293 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;
294  ?column? 
295 ----------
296  {}
297 (1 row)
298
299 -- known issues !!!!
300 -- lookups of lhs values in rhs jsonb use findJsonbValueFromContainer which does not allow looking up non-scalar elements resulting in "invalid jsonb scalar type"
301 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '[[1]]'::jsonb;
302 ERROR:  invalid jsonb scalar type
303 SELECT '["a",2,{"a":1, "b":2}]'::jsonb - '[{"a":1}]'::jsonb;
304 ERROR:  invalid jsonb scalar type
305 -------------------------------------------------------------------------------
306 -- Tests for jsonb || jsonb
307 -------------------------------------------------------------------------------
308 -- duplicates should automatically be removed by lower level logic
309 SELECT '{"a": 1, "b": 2, "c": 3}'::jsonb || '{"a": 4, "b": 2, "d": 4}'::jsonb;
310              ?column?             
311 ----------------------------------
312  {"a": 4, "b": 2, "c": 3, "d": 4}
313 (1 row)
314
315 -- concatentation of arrays
316 SELECT '["a", "b"]'::jsonb || '["c"]'::jsonb;
317     ?column?     
318 -----------------
319  ["a", "b", "c"]
320 (1 row)
321
322 -- concatentation of scalars and arrays should be wrapped into arrays
323 SELECT '["a", "b"]'::jsonb || '"c"'::jsonb;
324     ?column?     
325 -----------------
326  ["a", "b", "c"]
327 (1 row)
328
329 -- likewise concatentation of objects and arrays should be wrapped into arrays
330 SELECT '["a", "b"]'::jsonb || '{"a": 4, "b": 2}'::jsonb;
331            ?column?           
332 ------------------------------
333  ["a", "b", {"a": 4, "b": 2}]
334 (1 row)
335
336 -- and all concatentation should be in natural order supplied
337 SELECT '{"a": 4, "b": 2}'::jsonb || '["a", "b"]'::jsonb || '["c", "d"]'::jsonb;
338                 ?column?                
339 ----------------------------------------
340  [{"a": 4, "b": 2}, "a", "b", "c", "d"]
341 (1 row)
342
343 -- others
344 SELECT 'false'::jsonb || '["a", "b"]'::jsonb || '["c", "d"]'::jsonb;
345           ?column?           
346 -----------------------------
347  [false, "a", "b", "c", "d"]
348 (1 row)
349
350 SELECT '["a","b"]'::jsonb || '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb;
351                         ?column?                        
352 --------------------------------------------------------
353  ["a", "b", {"a": {"b": 3, "c": [1, 2, 3, 4]}, "d": 2}]
354 (1 row)
355
356 SELECT '{"a":{"b":3, "c":[1,2,3,4]}, "d":2}'::jsonb || '["a","b"]'::jsonb;
357                         ?column?                        
358 --------------------------------------------------------
359  [{"a": {"b": 3, "c": [1, 2, 3, 4]}, "d": 2}, "a", "b"]
360 (1 row)
361
362 -------------------------------------------------------------------------------
363 -- Tests for jsonb =# jsonb
364 -------------------------------------------------------------------------------
365 -- any keys existing in left argument have values replaced with those from righ argument
366 SELECT '{"a": 1, "b": 2, "c":[1,2,3], "d":{"test":false}}'::jsonb #= '{"a": [1,2,3,4], "b": {"f":100, "j":{"k":200}}, "c": 4, "d":{"test":true}}'::jsonb;
367                                       ?column?                                      
368 ------------------------------------------------------------------------------------
369  {"a": [1, 2, 3, 4], "b": {"f": 100, "j": {"k": 200}}, "c": 4, "d": {"test": true}}
370 (1 row)
371
372 -- note that as we are matching only keys and replacing values operation on an scalar/array elements effectively does nothing 
373 SELECT '{"a":[1,2], "b":2, "c":12}'::jsonb #= '["a","b","c"]'::jsonb;
374             ?column?            
375 --------------------------------
376  {"a": [1, 2], "b": 2, "c": 12}
377 (1 row)
378
379 SELECT '{"a":[1,2], "b":2, "c":12}'::jsonb #= '[1,2,3]'::jsonb;
380             ?column?            
381 --------------------------------
382  {"a": [1, 2], "b": 2, "c": 12}
383 (1 row)
384
385 SELECT '[1,2,3]'::jsonb #= '[1,2,3,4]'::jsonb;
386  ?column?  
387 -----------
388  [1, 2, 3]
389 (1 row)
390
391 SELECT '"a"'::jsonb #= '{"a":1, "b":2}'::jsonb;
392  ?column? 
393 ----------
394  "a"
395 (1 row)
396
397 SELECT '{"a":1, "b":2}'::jsonb #= '"a"'::jsonb;
398      ?column?     
399 ------------------
400  {"a": 1, "b": 2}
401 (1 row)
402
403 -------------------------------------------------------------------------------
404 -- Tests for jsonb #- text[] 
405 -------------------------------------------------------------------------------
406 SELECT '"a"'::jsonb #- ARRAY['b'];
407  ?column? 
408 ----------
409  "a"
410 (1 row)
411
412 SELECT '["a"]'::jsonb #- ARRAY['b'];
413  ?column? 
414 ----------
415  ["a"]
416 (1 row)
417
418 SELECT '{"a":1}'::jsonb #- ARRAY['b'];
419  ?column? 
420 ----------
421  {"a": 1}
422 (1 row)
423
424 SELECT '"a"'::jsonb #- ARRAY['a'];
425  ?column? 
426 ----------
427  
428 (1 row)
429
430 SELECT '["a"]'::jsonb #- ARRAY['a'];
431  ?column? 
432 ----------
433  []
434 (1 row)
435
436 SELECT '{"a":1}'::jsonb #- ARRAY['a'];
437  ?column? 
438 ----------
439  {}
440 (1 row)
441
442 SELECT '["a", "b"]'::jsonb #- ARRAY['a'];
443  ?column? 
444 ----------
445  ["b"]
446 (1 row)
447
448 SELECT '{"a":1, "b":2}'::jsonb #- ARRAY['a'];
449  ?column? 
450 ----------
451  {"b": 2}
452 (1 row)
453
454 SELECT '{"a":{"b":1}, "c":2}'::jsonb #- ARRAY['a'];
455  ?column? 
456 ----------
457  {"c": 2}
458 (1 row)
459
460 SELECT '{"a":[1,2,3,4], "b":2}'::jsonb #- ARRAY['a'];
461  ?column? 
462 ----------
463  {"b": 2}
464 (1 row)
465
466 SELECT '{"a":[1,2,3,4], "b":2}'::jsonb #- ARRAY['b'];
467       ?column?       
468 ---------------------
469  {"a": [1, 2, 3, 4]}
470 (1 row)
471
472 SELECT '{"a":{"b":[1,2,3,["a","b"]]}, "c":2}'::jsonb #- ARRAY['c'];
473               ?column?               
474 -------------------------------------
475  {"a": {"b": [1, 2, 3, ["a", "b"]]}}
476 (1 row)
477
478 SELECT '{"a":{"b":[1,2,3,["a","b"]]}, "c":2}'::jsonb #- ARRAY['a'];
479  ?column? 
480 ----------
481  {"c": 2}
482 (1 row)
483
484 SELECT '{"a":{"b":[1,2,3,["a","b"]]}, "c":2}'::jsonb #- ARRAY['a','c'];
485                   ?column?                   
486 ---------------------------------------------
487  {"a": {"b": [1, 2, 3, ["a", "b"]]}, "c": 2}
488 (1 row)
489
490 SELECT '{"a":{"b":[1,2,3,["a","b"]]}, "c":2}'::jsonb #- ARRAY['a','b'];
491      ?column?      
492 -------------------
493  {"a": {}, "c": 2}
494 (1 row)
495
496 SELECT '{"a":{"b":[1,2,3,["a","b"]]}, "c":2}'::jsonb #- ARRAY['a','b','c'];
497                   ?column?                   
498 ---------------------------------------------
499  {"a": {"b": [1, 2, 3, ["a", "b"]]}, "c": 2}
500 (1 row)
501
502 SELECT '{"a":{"b":{"c":1}, "c":[1,2,3,["a","b"]]}, "d":3}'::jsonb #- ARRAY['a','b','c'];
503                        ?column?                       
504 ------------------------------------------------------
505  {"a": {"b": {}, "c": [1, 2, 3, ["a", "b"]]}, "d": 3}
506 (1 row)
507
508 SELECT '{"a":{"b":[1,2,3,["a","b"]], "c":[1,2,3,4]}, "d":2}'::jsonb #- ARRAY['a','b'];
509               ?column?              
510 ------------------------------------
511  {"a": {"c": [1, 2, 3, 4]}, "d": 2}
512 (1 row)
513
514 SELECT '{"a":{"b":[1,2,3,["a","b"]], "c":[1,2,3,4]}, "d":2}'::jsonb #- ARRAY['a','c'];
515                   ?column?                   
516 ---------------------------------------------
517  {"a": {"b": [1, 2, 3, ["a", "b"]]}, "d": 2}
518 (1 row)
519
520 SELECT '{"a":{"b":[1,2,3,["a","b"]], "c":[1,2,3,4]}, "d":2}'::jsonb #- ARRAY['a',null];
521                             ?column?                            
522 ----------------------------------------------------------------
523  {"a": {"b": [1, 2, 3, ["a", "b"]], "c": [1, 2, 3, 4]}, "d": 2}
524 (1 row)
525
526 SELECT '{"a":{"b":[1,2,3,["a",{"b":3}]], "c":[1,2,3,4]}, "d":2}'::jsonb #- ARRAY['a','b'];
527               ?column?              
528 ------------------------------------
529  {"a": {"c": [1, 2, 3, 4]}, "d": 2}
530 (1 row)
531
532 SELECT '{"a":{"b":3, "d":[1,{"Z":[1,[2,3]]}]}}'::jsonb #- ARRAY['a','d'];
533     ?column?     
534 -----------------
535  {"a": {"b": 3}}
536 (1 row)
537
538 SELECT '["a", {"b":[1,2,3,4,5]}, 1, "c"]'::jsonb #- ARRAY['a'];
539              ?column?             
540 ----------------------------------
541  [{"b": [1, 2, 3, 4, 5]}, 1, "c"]
542 (1 row)
543
544 SELECT '["a", {"b":[1,2,3,4,5]}, 1, "c"]'::jsonb #- ARRAY['c'];
545              ?column?             
546 ----------------------------------
547  ["a", {"b": [1, 2, 3, 4, 5]}, 1]
548 (1 row)
549
550 SELECT '[1,[2,[3,[4,[5,6,7]]]],"a","b"]'::jsonb #- ARRAY['b'];
551               ?column?              
552 ------------------------------------
553  [1, [2, [3, [4, [5, 6, 7]]]], "a"]
554 (1 row)
555
556 SELECT '[1,[2,[3,[4,[5,6,7]]]],"a","b"]'::jsonb #- ARRAY['a'];
557               ?column?              
558 ------------------------------------
559  [1, [2, [3, [4, [5, 6, 7]]]], "b"]
560 (1 row)
561
562 -- expected limitation: cannot call with path deeper than 1 on a non-object
563 SELECT '["a", "b"]'::jsonb #- ARRAY['a','b'];
564 ERROR:  cannot call with path deeper than 1 on a non-object
565 -------------------------------------------------------------------------------
566 -- Tests for jsonb_replace_path jsonb text[] 
567 -------------------------------------------------------------------------------
568 SELECT jsonb_replace_path('{"a":1, "b":2}', ARRAY['a'], '{"f":3}'::jsonb);
569  jsonb_replace_path 
570 --------------------
571  {"b": 2, "f": 3}
572 (1 row)
573
574 SELECT jsonb_replace_path('{"a":{"b":1}}', ARRAY['a'], '{"f":3}'::jsonb);
575  jsonb_replace_path 
576 --------------------
577  {"f": 3}
578 (1 row)
579
580 SELECT jsonb_replace_path('{"a":{"b":1}}', ARRAY['a','b'], '{"f":3}'::jsonb);
581  jsonb_replace_path 
582 --------------------
583  {"a": {"f": 3}}
584 (1 row)
585
586 SELECT jsonb_replace_path('{"a":{"b":1, "c":1}}', ARRAY['a','b'], '{"f":3}'::jsonb);
587    jsonb_replace_path    
588 -------------------------
589  {"a": {"c": 1, "f": 3}}
590 (1 row)
591
592 SELECT jsonb_replace_path('{"a":{"b":1, "c":1}}', ARRAY['a','c'], '{"f":3}'::jsonb);
593    jsonb_replace_path    
594 -------------------------
595  {"a": {"b": 1, "f": 3}}
596 (1 row)
597
598 SELECT jsonb_replace_path('{"a":{"b":1, "c":2, "d":[1,2]}}', ARRAY['a','b'], '{"f":3}'::jsonb);
599           jsonb_replace_path          
600 --------------------------------------
601  {"a": {"c": 2, "d": [1, 2], "f": 3}}
602 (1 row)
603
604 SELECT jsonb_replace_path('{"a":{"b":1, "c":2, "d":[1,2]}}', ARRAY['a','c'], '{"f":3}'::jsonb);
605           jsonb_replace_path          
606 --------------------------------------
607  {"a": {"b": 1, "d": [1, 2], "f": 3}}
608 (1 row)
609
610 SELECT jsonb_replace_path('{"a":{"b":1, "c":2, "d":[1,2]}}', ARRAY['a','d'], '{"f":3}'::jsonb);
611        jsonb_replace_path        
612 ---------------------------------
613  {"a": {"b": 1, "c": 2, "f": 3}}
614 (1 row)
615
616 SELECT jsonb_replace_path('{"a":{"d":[1,{"Z":[1,[2,3]]}]}}', ARRAY['a','d'], '{"f":3}'::jsonb);
617  jsonb_replace_path 
618 --------------------
619  {"a": {"f": 3}}
620 (1 row)
621
622 SELECT jsonb_replace_path('{"a":{"b":1, "c":2, "d":[1,{"Z":[1,[2,3]]}]}}', ARRAY['a','b'], '{"f":3}'::jsonb);
623                   jsonb_replace_path                   
624 -------------------------------------------------------
625  {"a": {"c": 2, "d": [1, {"Z": [1, [2, 3]]}], "f": 3}}
626 (1 row)
627
628 SELECT jsonb_replace_path('{"a":{"b":1, "c":2, "d":[1,{"Z":[1,[2,3]]}]}}', ARRAY['a','c'], '{"f":3}'::jsonb);
629                   jsonb_replace_path                   
630 -------------------------------------------------------
631  {"a": {"b": 1, "d": [1, {"Z": [1, [2, 3]]}], "f": 3}}
632 (1 row)
633
634 SELECT jsonb_replace_path('{"a":{"b":1, "c":2, "d":[1,{"Z":[1,[2,3]]}]}}', ARRAY['a','d'], '{"f":3}'::jsonb);
635        jsonb_replace_path        
636 ---------------------------------
637  {"a": {"b": 1, "c": 2, "f": 3}}
638 (1 row)
639
640 SELECT jsonb_replace_path('{"a":1, "b":null, "c":[1,2,null], "c":{"d":11}, "e":{"20":[100,"c"]}}', ARRAY['c'], '{"f":[[1],2], "g":"test", "h":{"i":{"j":null}}}');
641                                         jsonb_replace_path                                         
642 ---------------------------------------------------------------------------------------------------
643  {"a": 1, "b": null, "e": {"20": [100, "c"]}, "f": [[1], 2], "g": "test", "h": {"i": {"j": null}}}
644 (1 row)
645
646 SELECT jsonb_replace_path('"a"', ARRAY['a'], '{"f":10}'::jsonb); 
647  jsonb_replace_path 
648 --------------------
649  {"f": 10}
650 (1 row)
651
652 SELECT jsonb_replace_path('"a"', ARRAY['z'], '{"f":10}'::jsonb); 
653  jsonb_replace_path 
654 --------------------
655  "a"
656 (1 row)
657
658 SELECT jsonb_replace_path('[null, "a"]', ARRAY[null], '"b"'::jsonb); 
659  jsonb_replace_path 
660 --------------------
661  ["b", "a"]
662 (1 row)
663
664 SELECT jsonb_replace_path('[1,2,3,"4"]', ARRAY['4'], '"5"'::jsonb); 
665  jsonb_replace_path 
666 --------------------
667  "5"
668 (1 row)
669