@@ -4346,24 +4346,6 @@ transformJsonArrayConstructor(ParseState *pstate, JsonArrayConstructor *ctor)
4346
4346
ctor -> location );
4347
4347
}
4348
4348
4349
- static const char *
4350
- JsonValueTypeStrings [] =
4351
- {
4352
- "any" ,
4353
- "object" ,
4354
- "array" ,
4355
- "scalar" ,
4356
- };
4357
-
4358
- static Const *
4359
- makeJsonValueTypeConst (JsonValueType type )
4360
- {
4361
- return makeConst (TEXTOID , -1 , InvalidOid , -1 ,
4362
- PointerGetDatum (cstring_to_text (
4363
- JsonValueTypeStrings [(int ) type ])),
4364
- false, false);
4365
- }
4366
-
4367
4349
/*
4368
4350
* Transform IS JSON predicate into
4369
4351
* json[b]_is_valid(json, value_type [, check_key_uniqueness]) call.
@@ -4373,7 +4355,6 @@ transformJsonIsPredicate(ParseState *pstate, JsonIsPredicate *pred)
4373
4355
{
4374
4356
Node * expr = transformExprRecurse (pstate , pred -> expr );
4375
4357
Oid exprtype = exprType (expr );
4376
- FuncExpr * fexpr ;
4377
4358
4378
4359
/* prepare input document */
4379
4360
if (exprtype == BYTEAOID )
@@ -4408,38 +4389,12 @@ transformJsonIsPredicate(ParseState *pstate, JsonIsPredicate *pred)
4408
4389
expr = (Node * ) makeJsonValueExpr ((Expr * ) expr , pred -> format );
4409
4390
4410
4391
/* make resulting expression */
4411
- if (exprtype == TEXTOID || exprtype == JSONOID )
4412
- {
4413
- fexpr = makeFuncExpr (F_JSON_IS_VALID , BOOLOID ,
4414
- list_make3 (expr ,
4415
- makeJsonValueTypeConst (pred -> value_type ),
4416
- makeBoolConst (pred -> unique_keys , false)),
4417
- InvalidOid , InvalidOid , COERCE_EXPLICIT_CALL );
4418
-
4419
- fexpr -> location = pred -> location ;
4420
- }
4421
- else if (exprtype == JSONBOID )
4422
- {
4423
- /* XXX the following expressions also can be used here:
4424
- * jsonb_type(jsonb) = 'type' (for object and array checks)
4425
- * CASE jsonb_type(jsonb) WHEN ... END (for scalars checks)
4426
- */
4427
- fexpr = makeFuncExpr (F_JSONB_IS_VALID , BOOLOID ,
4428
- list_make2 (expr ,
4429
- makeJsonValueTypeConst (pred -> value_type )),
4430
- InvalidOid , InvalidOid , COERCE_EXPLICIT_CALL );
4431
-
4432
- fexpr -> location = pred -> location ;
4433
- }
4434
- else
4435
- {
4392
+ if (exprtype != TEXTOID && exprtype != JSONOID && exprtype != JSONBOID )
4436
4393
ereport (ERROR ,
4437
4394
(errcode (ERRCODE_DATATYPE_MISMATCH ),
4438
4395
errmsg ("cannot use type %s in IS JSON predicate" ,
4439
4396
format_type_be (exprtype ))));
4440
- return NULL ;
4441
- }
4442
4397
4443
- return makeJsonIsPredicate ((Node * ) fexpr , NULL , pred -> value_type ,
4444
- pred -> unique_keys );
4398
+ return makeJsonIsPredicate ((Node * ) expr , NULL , pred -> value_type ,
4399
+ pred -> unique_keys , pred -> location );
4445
4400
}
0 commit comments