Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a137ab

Browse files
committed
Add more test coverage for jsonpath "$.*" with arrays
There was no coverage for the code path to unwrap an array beforeapplying ".*" to it, so add tests to provide more coverage for bothobjects and arrays.This shows, for example, that no results are returned for an array ofscalars, and what results are returned when the array contains anobject. A few more scenarios are covered with the strict/lax modes andthe operator "@?".Author: David WheelerReported-by: David G. Johnston, Stepan NeretinDiscussion:https://postgr.es/m/A95346F9-6147-46E0-809E-532A485D71D6@justatheory.com
1 parent5c571a3 commit3a137ab

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

‎src/test/regress/expected/jsonb_jsonpath.out

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,56 @@ select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', silent => true);
11351135
------------------
11361136
(0 rows)
11371137

1138+
-- any key on arrays with and without unwrapping.
1139+
select jsonb_path_query('{"a": [1,2,3], "b": [3,4,5]}', '$.*');
1140+
jsonb_path_query
1141+
------------------
1142+
[1, 2, 3]
1143+
[3, 4, 5]
1144+
(2 rows)
1145+
1146+
select jsonb_path_query('[1,2,3]', '$.*');
1147+
jsonb_path_query
1148+
------------------
1149+
(0 rows)
1150+
1151+
select jsonb_path_query('[1,2,3,{"b": [3,4,5]}]', 'lax $.*');
1152+
jsonb_path_query
1153+
------------------
1154+
[3, 4, 5]
1155+
(1 row)
1156+
1157+
select jsonb_path_query('[1,2,3,{"b": [3,4,5]}]', 'strict $.*');
1158+
ERROR: jsonpath wildcard member accessor can only be applied to an object
1159+
select jsonb_path_query('[1,2,3,{"b": [3,4,5]}]', 'strict $.*', NULL, true);
1160+
jsonb_path_query
1161+
------------------
1162+
(0 rows)
1163+
1164+
select jsonb '{"a": [1,2,3], "b": [3,4,5]}' @? '$.*';
1165+
?column?
1166+
----------
1167+
t
1168+
(1 row)
1169+
1170+
select jsonb '[1,2,3]' @? '$.*';
1171+
?column?
1172+
----------
1173+
f
1174+
(1 row)
1175+
1176+
select jsonb '[1,2,3,{"b": [3,4,5]}]' @? 'lax $.*';
1177+
?column?
1178+
----------
1179+
t
1180+
(1 row)
1181+
1182+
select jsonb '[1,2,3,{"b": [3,4,5]}]' @? 'strict $.*';
1183+
?column?
1184+
----------
1185+
1186+
(1 row)
1187+
11381188
-- extension: boolean expressions
11391189
select jsonb_path_query('2', '$ > 1');
11401190
jsonb_path_query

‎src/test/regress/sql/jsonb_jsonpath.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ select jsonb_path_query('{"a": [2, 3, 4]}', 'lax -$.a');
241241
select jsonb_path_query('{"a": [1, 2]}','lax $.a * 3');
242242
select jsonb_path_query('{"a": [1, 2]}','lax $.a * 3', silent=> true);
243243

244+
-- any key on arrays with and without unwrapping.
245+
select jsonb_path_query('{"a": [1,2,3], "b": [3,4,5]}','$.*');
246+
select jsonb_path_query('[1,2,3]','$.*');
247+
select jsonb_path_query('[1,2,3,{"b": [3,4,5]}]','lax $.*');
248+
select jsonb_path_query('[1,2,3,{"b": [3,4,5]}]','strict $.*');
249+
select jsonb_path_query('[1,2,3,{"b": [3,4,5]}]','strict $.*',NULL, true);
250+
select jsonb'{"a": [1,2,3], "b": [3,4,5]}' @?'$.*';
251+
select jsonb'[1,2,3]' @?'$.*';
252+
select jsonb'[1,2,3,{"b": [3,4,5]}]' @?'lax $.*';
253+
select jsonb'[1,2,3,{"b": [3,4,5]}]' @?'strict $.*';
254+
244255
-- extension: boolean expressions
245256
select jsonb_path_query('2','$ > 1');
246257
select jsonb_path_query('2','$ <= 1');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp