@@ -200,8 +200,8 @@ add_gin_entry(GinEntries *entries, Datum entry)
200
200
*
201
201
*/
202
202
203
- Datum
204
- gin_compare_jsonb ( PG_FUNCTION_ARGS )
203
+ static Datum
204
+ gin_compare_json_internal ( FunctionCallInfo fcinfo )
205
205
{
206
206
text * arg1 = PG_GETARG_TEXT_PP (0 );
207
207
text * arg2 = PG_GETARG_TEXT_PP (1 );
@@ -227,10 +227,20 @@ gin_compare_jsonb(PG_FUNCTION_ARGS)
227
227
}
228
228
229
229
Datum
230
- gin_extract_jsonb (PG_FUNCTION_ARGS )
230
+ gin_compare_jsonb (PG_FUNCTION_ARGS )
231
+ {
232
+ return gin_compare_json_internal (fcinfo );
233
+ }
234
+
235
+ Datum
236
+ gin_compare_json (PG_FUNCTION_ARGS )/* XXX remove */
237
+ {
238
+ return gin_compare_json_internal (fcinfo );
239
+ }
240
+
241
+ static Datum *
242
+ gin_extract_json_internal (Json * jb ,int32 * nentries )
231
243
{
232
- Jsonb * jb = (Jsonb * )PG_GETARG_JSONB_P (0 );
233
- int32 * nentries = (int32 * )PG_GETARG_POINTER (1 );
234
244
int total = JB_ROOT_COUNT (jb );
235
245
JsonbIterator * it ;
236
246
JsonbValue v ;
@@ -241,7 +251,7 @@ gin_extract_jsonb(PG_FUNCTION_ARGS)
241
251
if (total == 0 )
242
252
{
243
253
* nentries = 0 ;
244
- PG_RETURN_POINTER ( NULL ) ;
254
+ return NULL ;
245
255
}
246
256
247
257
if (total < 0 )
@@ -274,7 +284,21 @@ gin_extract_jsonb(PG_FUNCTION_ARGS)
274
284
275
285
* nentries = entries .count ;
276
286
277
- PG_RETURN_POINTER (entries .buf );
287
+ return entries .buf ;
288
+ }
289
+
290
+ Datum
291
+ gin_extract_jsonb (PG_FUNCTION_ARGS )
292
+ {
293
+ PG_RETURN_POINTER (gin_extract_json_internal (PG_GETARG_JSONB_P (0 ),
294
+ (int32 * )PG_GETARG_POINTER (1 )));
295
+ }
296
+
297
+ Datum
298
+ gin_extract_json (PG_FUNCTION_ARGS )
299
+ {
300
+ PG_RETURN_POINTER (gin_extract_json_internal (PG_GETARG_JSONT_P (0 ),
301
+ (int32 * )PG_GETARG_POINTER (1 )));
278
302
}
279
303
280
304
/* Append JsonPathGinPathItem to JsonPathGinPath (jsonb_ops) */
@@ -848,8 +872,8 @@ execute_jsp_gin_node(JsonPathGinNode *node, void *check, bool ternary)
848
872
}
849
873
}
850
874
851
- Datum
852
- gin_extract_jsonb_query ( PG_FUNCTION_ARGS )
875
+ static Datum
876
+ gin_extract_json_query_internal ( FunctionCallInfo fcinfo , bool is_jsonb )
853
877
{
854
878
int32 * nentries = (int32 * )PG_GETARG_POINTER (1 );
855
879
StrategyNumber strategy = PG_GETARG_UINT16 (2 );
@@ -860,7 +884,9 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
860
884
{
861
885
/* Query is a jsonb, so just apply gin_extract_jsonb... */
862
886
entries = (Datum * )
863
- DatumGetPointer (DirectFunctionCall2 (gin_extract_jsonb ,
887
+ DatumGetPointer (DirectFunctionCall2 (is_jsonb ?
888
+ gin_extract_jsonb :
889
+ gin_extract_json ,
864
890
PG_GETARG_DATUM (0 ),
865
891
PointerGetDatum (nentries )));
866
892
/* ...although "contains {}" requires a full index scan */
@@ -931,7 +957,19 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
931
957
}
932
958
933
959
Datum
934
- gin_consistent_jsonb (PG_FUNCTION_ARGS )
960
+ gin_extract_jsonb_query (PG_FUNCTION_ARGS )
961
+ {
962
+ return gin_extract_json_query_internal (fcinfo , true);
963
+ }
964
+
965
+ Datum
966
+ gin_extract_json_query (PG_FUNCTION_ARGS )
967
+ {
968
+ return gin_extract_json_query_internal (fcinfo , false);
969
+ }
970
+
971
+ static Datum
972
+ gin_consistent_json_internal (FunctionCallInfo fcinfo )
935
973
{
936
974
bool * check = (bool * )PG_GETARG_POINTER (0 );
937
975
StrategyNumber strategy = PG_GETARG_UINT16 (1 );
@@ -1015,7 +1053,19 @@ gin_consistent_jsonb(PG_FUNCTION_ARGS)
1015
1053
}
1016
1054
1017
1055
Datum
1018
- gin_triconsistent_jsonb (PG_FUNCTION_ARGS )
1056
+ gin_consistent_jsonb (PG_FUNCTION_ARGS )
1057
+ {
1058
+ return gin_consistent_json_internal (fcinfo );
1059
+ }
1060
+
1061
+ Datum
1062
+ gin_consistent_json (PG_FUNCTION_ARGS )
1063
+ {
1064
+ return gin_consistent_json_internal (fcinfo );
1065
+ }
1066
+
1067
+ static Datum
1068
+ gin_triconsistent_json_internal (FunctionCallInfo fcinfo )
1019
1069
{
1020
1070
GinTernaryValue * check = (GinTernaryValue * )PG_GETARG_POINTER (0 );
1021
1071
StrategyNumber strategy = PG_GETARG_UINT16 (1 );
@@ -1079,6 +1129,18 @@ gin_triconsistent_jsonb(PG_FUNCTION_ARGS)
1079
1129
PG_RETURN_GIN_TERNARY_VALUE (res );
1080
1130
}
1081
1131
1132
+ Datum
1133
+ gin_triconsistent_jsonb (PG_FUNCTION_ARGS )
1134
+ {
1135
+ return gin_triconsistent_json_internal (fcinfo );
1136
+ }
1137
+
1138
+ Datum
1139
+ gin_triconsistent_json (PG_FUNCTION_ARGS )
1140
+ {
1141
+ return gin_triconsistent_json_internal (fcinfo );
1142
+ }
1143
+
1082
1144
/*
1083
1145
*
1084
1146
* jsonb_path_ops GIN opclass support functions
@@ -1091,11 +1153,9 @@ gin_triconsistent_jsonb(PG_FUNCTION_ARGS)
1091
1153
*
1092
1154
*/
1093
1155
1094
- Datum
1095
- gin_extract_jsonb_path ( PG_FUNCTION_ARGS )
1156
+ static Datum *
1157
+ gin_extract_json_path_internal ( Json * jb , int32 * nentries )
1096
1158
{
1097
- Jsonb * jb = PG_GETARG_JSONB_P (0 );
1098
- int32 * nentries = (int32 * )PG_GETARG_POINTER (1 );
1099
1159
int total = JB_ROOT_COUNT (jb );
1100
1160
JsonbIterator * it ;
1101
1161
JsonbValue v ;
@@ -1108,7 +1168,7 @@ gin_extract_jsonb_path(PG_FUNCTION_ARGS)
1108
1168
if (total == 0 )
1109
1169
{
1110
1170
* nentries = 0 ;
1111
- PG_RETURN_POINTER ( NULL ) ;
1171
+ return NULL ;
1112
1172
}
1113
1173
1114
1174
if (total < 0 )
@@ -1181,11 +1241,25 @@ gin_extract_jsonb_path(PG_FUNCTION_ARGS)
1181
1241
1182
1242
* nentries = entries .count ;
1183
1243
1184
- PG_RETURN_POINTER ( entries .buf ) ;
1244
+ return entries .buf ;
1185
1245
}
1186
1246
1187
1247
Datum
1188
- gin_extract_jsonb_query_path (PG_FUNCTION_ARGS )
1248
+ gin_extract_jsonb_path (PG_FUNCTION_ARGS )
1249
+ {
1250
+ PG_RETURN_POINTER (gin_extract_json_path_internal (PG_GETARG_JSONB_P (0 ),
1251
+ (int32 * )PG_GETARG_POINTER (1 )));
1252
+ }
1253
+
1254
+ Datum
1255
+ gin_extract_json_path (PG_FUNCTION_ARGS )
1256
+ {
1257
+ PG_RETURN_POINTER (gin_extract_json_path_internal (PG_GETARG_JSONT_P (0 ),
1258
+ (int32 * )PG_GETARG_POINTER (1 )));
1259
+ }
1260
+
1261
+ static Datum
1262
+ gin_extract_json_query_path_internal (FunctionCallInfo fcinfo ,bool is_jsonb )
1189
1263
{
1190
1264
int32 * nentries = (int32 * )PG_GETARG_POINTER (1 );
1191
1265
StrategyNumber strategy = PG_GETARG_UINT16 (2 );
@@ -1196,7 +1270,9 @@ gin_extract_jsonb_query_path(PG_FUNCTION_ARGS)
1196
1270
{
1197
1271
/* Query is a jsonb, so just apply gin_extract_jsonb_path ... */
1198
1272
entries = (Datum * )
1199
- DatumGetPointer (DirectFunctionCall2 (gin_extract_jsonb_path ,
1273
+ DatumGetPointer (DirectFunctionCall2 (is_jsonb ?
1274
+ gin_extract_jsonb_path :
1275
+ gin_extract_json_path ,
1200
1276
PG_GETARG_DATUM (0 ),
1201
1277
PointerGetDatum (nentries )));
1202
1278
@@ -1225,7 +1301,19 @@ gin_extract_jsonb_query_path(PG_FUNCTION_ARGS)
1225
1301
}
1226
1302
1227
1303
Datum
1228
- gin_consistent_jsonb_path (PG_FUNCTION_ARGS )
1304
+ gin_extract_jsonb_query_path (PG_FUNCTION_ARGS )
1305
+ {
1306
+ return gin_extract_json_query_path_internal (fcinfo , true);
1307
+ }
1308
+
1309
+ Datum
1310
+ gin_extract_json_query_path (PG_FUNCTION_ARGS )
1311
+ {
1312
+ return gin_extract_json_query_path_internal (fcinfo , false);
1313
+ }
1314
+
1315
+ static Datum
1316
+ gin_consistent_json_path_internal (FunctionCallInfo fcinfo )
1229
1317
{
1230
1318
bool * check = (bool * )PG_GETARG_POINTER (0 );
1231
1319
StrategyNumber strategy = PG_GETARG_UINT16 (1 );
@@ -1277,7 +1365,19 @@ gin_consistent_jsonb_path(PG_FUNCTION_ARGS)
1277
1365
}
1278
1366
1279
1367
Datum
1280
- gin_triconsistent_jsonb_path (PG_FUNCTION_ARGS )
1368
+ gin_consistent_jsonb_path (PG_FUNCTION_ARGS )
1369
+ {
1370
+ return gin_consistent_json_path_internal (fcinfo );
1371
+ }
1372
+
1373
+ Datum
1374
+ gin_consistent_json_path (PG_FUNCTION_ARGS )
1375
+ {
1376
+ return gin_consistent_json_path_internal (fcinfo );
1377
+ }
1378
+
1379
+ static Datum
1380
+ gin_triconsistent_json_path_internal (FunctionCallInfo fcinfo )
1281
1381
{
1282
1382
GinTernaryValue * check = (GinTernaryValue * )PG_GETARG_POINTER (0 );
1283
1383
StrategyNumber strategy = PG_GETARG_UINT16 (1 );
@@ -1324,6 +1424,18 @@ gin_triconsistent_jsonb_path(PG_FUNCTION_ARGS)
1324
1424
PG_RETURN_GIN_TERNARY_VALUE (res );
1325
1425
}
1326
1426
1427
+ Datum
1428
+ gin_triconsistent_jsonb_path (PG_FUNCTION_ARGS )
1429
+ {
1430
+ return gin_triconsistent_json_path_internal (fcinfo );
1431
+ }
1432
+
1433
+ Datum
1434
+ gin_triconsistent_json_path (PG_FUNCTION_ARGS )
1435
+ {
1436
+ return gin_triconsistent_json_path_internal (fcinfo );
1437
+ }
1438
+
1327
1439
/*
1328
1440
* Construct a jsonb_ops GIN key from a flag byte and a textual representation
1329
1441
* (which need not be null-terminated). This function is responsible