@@ -4346,28 +4346,25 @@ transformJsonArrayConstructor(ParseState *pstate, JsonArrayConstructor *ctor)
4346
4346
ctor -> location );
4347
4347
}
4348
4348
4349
- /*
4350
- * Transform IS JSON predicate into
4351
- * json[b]_is_valid(json, value_type [, check_key_uniqueness]) call.
4352
- */
4353
4349
static Node *
4354
- transformJsonIsPredicate (ParseState * pstate , JsonIsPredicate * pred )
4350
+ transformJsonParseArg (ParseState * pstate , Node * jsexpr , JsonFormat * format ,
4351
+ Oid * exprtype )
4355
4352
{
4356
- Node * raw_expr = transformExprRecurse (pstate , pred -> expr );
4353
+ Node * raw_expr = transformExprRecurse (pstate , jsexpr );
4357
4354
Node * expr = raw_expr ;
4358
- Oid exprtype = exprType (expr );
4355
+
4356
+ * exprtype = exprType (expr );
4359
4357
4360
4358
/* prepare input document */
4361
- if (exprtype == BYTEAOID )
4359
+ if (* exprtype == BYTEAOID )
4362
4360
{
4363
4361
JsonValueExpr * jve ;
4364
4362
4365
4363
expr = makeCaseTestExpr (raw_expr );
4366
- expr = makeJsonByteaToTextConversion (expr , pred -> format ,
4367
- exprLocation (expr ));
4368
- exprtype = TEXTOID ;
4364
+ expr = makeJsonByteaToTextConversion (expr , format , exprLocation (expr ));
4365
+ * exprtype = TEXTOID ;
4369
4366
4370
- jve = makeJsonValueExpr ((Expr * ) raw_expr , pred -> format );
4367
+ jve = makeJsonValueExpr ((Expr * ) raw_expr , format );
4371
4368
4372
4369
jve -> formatted_expr = (Expr * ) expr ;
4373
4370
expr = (Node * ) jve ;
@@ -4377,31 +4374,45 @@ transformJsonIsPredicate(ParseState *pstate, JsonIsPredicate *pred)
4377
4374
char typcategory ;
4378
4375
bool typispreferred ;
4379
4376
4380
- get_type_category_preferred (exprtype , & typcategory , & typispreferred );
4377
+ get_type_category_preferred (* exprtype , & typcategory , & typispreferred );
4381
4378
4382
- if (exprtype == UNKNOWNOID || typcategory == TYPCATEGORY_STRING )
4379
+ if (* exprtype == UNKNOWNOID || typcategory == TYPCATEGORY_STRING )
4383
4380
{
4384
- expr = coerce_to_target_type (pstate , (Node * ) expr , exprtype ,
4381
+ expr = coerce_to_target_type (pstate , (Node * ) expr , * exprtype ,
4385
4382
TEXTOID , -1 ,
4386
4383
COERCION_IMPLICIT ,
4387
4384
COERCE_IMPLICIT_CAST , -1 );
4388
- exprtype = TEXTOID ;
4385
+ * exprtype = TEXTOID ;
4389
4386
}
4390
4387
4391
- if (pred -> format -> encoding != JS_ENC_DEFAULT )
4388
+ if (format -> encoding != JS_ENC_DEFAULT )
4392
4389
ereport (ERROR ,
4393
4390
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
4394
- parser_errposition (pstate , pred -> format -> location ),
4391
+ parser_errposition (pstate , format -> location ),
4395
4392
errmsg ("cannot use JSON FORMAT ENCODING clause for non-bytea input types" )));
4396
4393
}
4397
4394
4395
+ return expr ;
4396
+ }
4397
+
4398
+ /*
4399
+ * Transform IS JSON predicate into
4400
+ * json[b]_is_valid(json, value_type [, check_key_uniqueness]) call.
4401
+ */
4402
+ static Node *
4403
+ transformJsonIsPredicate (ParseState * pstate , JsonIsPredicate * pred )
4404
+ {
4405
+ Oid exprtype ;
4406
+ Node * expr = transformJsonParseArg (pstate , pred -> expr , pred -> format ,
4407
+ & exprtype );
4408
+
4398
4409
/* make resulting expression */
4399
4410
if (exprtype != TEXTOID && exprtype != JSONOID && exprtype != JSONBOID )
4400
4411
ereport (ERROR ,
4401
4412
(errcode (ERRCODE_DATATYPE_MISMATCH ),
4402
4413
errmsg ("cannot use type %s in IS JSON predicate" ,
4403
4414
format_type_be (exprtype ))));
4404
4415
4405
- return makeJsonIsPredicate (( Node * ) expr , NULL , pred -> value_type ,
4416
+ return makeJsonIsPredicate (expr , NULL , pred -> value_type ,
4406
4417
pred -> unique_keys , pred -> location );
4407
4418
}
0 commit comments