21
21
#include "miscadmin.h"
22
22
#include "utils/builtins.h"
23
23
#include "utils/jsonb.h"
24
+ #include "utils/jsonpath.h"
24
25
25
26
#include "jsquery.h"
26
27
@@ -59,6 +60,7 @@ typedef struct
59
60
#define BLOOM_BITS 2
60
61
#define JsonbNestedContainsStrategyNumber 13
61
62
#define JsQueryMatchStrategyNumber 14
63
+ #define JsonpathExistsStrategyNumber 15
62
64
63
65
typedef struct
64
66
{
@@ -584,7 +586,8 @@ gin_compare_partial_jsonb_value_path(PG_FUNCTION_ARGS)
584
586
StrategyNumber strategy = PG_GETARG_UINT16 (2 );
585
587
int32 result ;
586
588
587
- if (strategy == JsQueryMatchStrategyNumber )
589
+ if (strategy == JsQueryMatchStrategyNumber ||
590
+ strategy == JsonpathExistsStrategyNumber )
588
591
{
589
592
KeyExtra * extra = (KeyExtra * )PG_GETARG_POINTER (3 );
590
593
ExtractedNode * node = extra -> node ;
@@ -780,7 +783,6 @@ gin_extract_jsonb_query_value_path(PG_FUNCTION_ARGS)
780
783
int i , n ;
781
784
uint32 * bloom ;
782
785
Entries e = {0 };
783
- JsQuery * jq ;
784
786
ExtractedNode * root ;
785
787
786
788
switch (strategy )
@@ -805,9 +807,20 @@ gin_extract_jsonb_query_value_path(PG_FUNCTION_ARGS)
805
807
break ;
806
808
807
809
case JsQueryMatchStrategyNumber :
808
- jq = PG_GETARG_JSQUERY (0 );
809
- root = extractJsQuery (jq , make_value_path_entry_handler ,
810
- check_value_path_entry_handler , (Pointer )& e );
810
+ #ifndef NO_JSONPATH
811
+ case JsonpathExistsStrategyNumber :
812
+ if (strategy == JsonpathExistsStrategyNumber )
813
+ root = extractJsonPath (PG_GETARG_JSONPATH_P (0 ),
814
+ make_value_path_entry_handler ,
815
+ check_value_path_entry_handler ,
816
+ (Pointer )& e );
817
+ else
818
+ #endif
819
+ root = extractJsQuery (PG_GETARG_JSQUERY (0 ),
820
+ make_value_path_entry_handler ,
821
+ check_value_path_entry_handler ,
822
+ (Pointer )& e );
823
+
811
824
if (root )
812
825
{
813
826
* nentries = e .count ;
@@ -864,6 +877,7 @@ gin_consistent_jsonb_value_path(PG_FUNCTION_ARGS)
864
877
break ;
865
878
866
879
case JsQueryMatchStrategyNumber :
880
+ case JsonpathExistsStrategyNumber :
867
881
if (nkeys == 0 )
868
882
res = true;
869
883
else
@@ -925,6 +939,7 @@ gin_triconsistent_jsonb_value_path(PG_FUNCTION_ARGS)
925
939
break ;
926
940
927
941
case JsQueryMatchStrategyNumber :
942
+ case JsonpathExistsStrategyNumber :
928
943
if (nkeys == 0 )
929
944
res = GIN_MAYBE ;
930
945
else
@@ -1047,7 +1062,8 @@ gin_compare_partial_jsonb_path_value(PG_FUNCTION_ARGS)
1047
1062
{
1048
1063
result = (key -> hash > partial_key -> hash ) ? 1 : -1 ;
1049
1064
}
1050
- else if (strategy == JsQueryMatchStrategyNumber )
1065
+ else if (strategy == JsQueryMatchStrategyNumber ||
1066
+ strategy == JsonpathExistsStrategyNumber )
1051
1067
{
1052
1068
KeyExtra * extra = (KeyExtra * )PG_GETARG_POINTER (3 );
1053
1069
ExtractedNode * node = extra -> node ;
@@ -1245,7 +1261,6 @@ gin_extract_jsonb_query_path_value_internal(FunctionCallInfo fcinfo, bool lax)
1245
1261
int i ;
1246
1262
Entries e = {0 };
1247
1263
PathValueExtra extra ;
1248
- JsQuery * jq ;
1249
1264
ExtractedNode * root ;
1250
1265
1251
1266
extra .entries = & e ;
@@ -1259,9 +1274,20 @@ gin_extract_jsonb_query_path_value_internal(FunctionCallInfo fcinfo, bool lax)
1259
1274
break ;
1260
1275
1261
1276
case JsQueryMatchStrategyNumber :
1262
- jq = PG_GETARG_JSQUERY (0 );
1263
- root = extractJsQuery (jq , make_path_value_entry_handler ,
1264
- check_path_value_entry_handler , (Pointer ) & extra );
1277
+ #ifndef NO_JSONPATH
1278
+ case JsonpathExistsStrategyNumber :
1279
+ if (strategy == JsonpathExistsStrategyNumber )
1280
+ root = extractJsonPath (PG_GETARG_JSONPATH_P (0 ),
1281
+ make_path_value_entry_handler ,
1282
+ check_path_value_entry_handler ,
1283
+ (Pointer ) & extra );
1284
+ else
1285
+ #endif
1286
+ root = extractJsQuery (PG_GETARG_JSQUERY (0 ),
1287
+ make_path_value_entry_handler ,
1288
+ check_path_value_entry_handler ,
1289
+ (Pointer ) & extra );
1290
+
1265
1291
if (root )
1266
1292
{
1267
1293
* nentries = e .count ;
@@ -1329,6 +1355,7 @@ gin_consistent_jsonb_path_value(PG_FUNCTION_ARGS)
1329
1355
break ;
1330
1356
1331
1357
case JsQueryMatchStrategyNumber :
1358
+ case JsonpathExistsStrategyNumber :
1332
1359
if (nkeys == 0 )
1333
1360
res = true;
1334
1361
else
@@ -1390,6 +1417,7 @@ gin_triconsistent_jsonb_path_value(PG_FUNCTION_ARGS)
1390
1417
break ;
1391
1418
1392
1419
case JsQueryMatchStrategyNumber :
1420
+ case JsonpathExistsStrategyNumber :
1393
1421
if (nkeys == 0 )
1394
1422
res = GIN_MAYBE ;
1395
1423
else
0 commit comments