From 6fb46f97030adc59f7f8d5313264ef1c6a95b062 Mon Sep 17 00:00:00 2001 From: jian he Date: Thu, 10 Jul 2025 15:43:18 +0800 Subject: [PATCH v12 1/1] minor refactor coerce_jsonpath_subscript --- src/backend/utils/adt/jsonbsubs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/adt/jsonbsubs.c b/src/backend/utils/adt/jsonbsubs.c index 5d0ec6bf2fa..7a14f506c92 100644 --- a/src/backend/utils/adt/jsonbsubs.c +++ b/src/backend/utils/adt/jsonbsubs.c @@ -33,14 +33,14 @@ typedef struct JsonbSubWorkspace } JsonbSubWorkspace; static Node * -coerce_jsonpath_subscript(ParseState *pstate, Node *subExpr, Oid numtype) +coerce_jsonpath_subscript(ParseState *pstate, Node *subExpr) { Oid subExprType = exprType(subExpr); - Oid targetType = UNKNOWNOID; + Oid targetType = InvalidOid; if (subExprType != UNKNOWNOID) { - Oid targets[2] = {numtype, TEXTOID}; + Oid targets[2] = {INT4OID, TEXTOID}; /* * Jsonb can handle multiple subscript types, but cases when a @@ -56,7 +56,7 @@ coerce_jsonpath_subscript(ParseState *pstate, Node *subExpr, Oid numtype) * One type has already succeeded, it means there are two * coercion targets possible, failure. */ - if (targetType != UNKNOWNOID) + if (OidIsValid(targetType)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("subscript type %s is not supported", format_type_be(subExprType)), @@ -70,7 +70,7 @@ coerce_jsonpath_subscript(ParseState *pstate, Node *subExpr, Oid numtype) /* * No suitable types were found, failure. */ - if (targetType == UNKNOWNOID) + if (!OidIsValid(targetType)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("subscript type %s is not supported", format_type_be(subExprType)), @@ -139,7 +139,7 @@ jsonb_subscript_transform(SubscriptingRef *sbsref, if (ai->uidx) { subExpr = transformExpr(pstate, ai->uidx, pstate->p_expr_kind); - subExpr = coerce_jsonpath_subscript(pstate, subExpr, INT4OID); + subExpr = coerce_jsonpath_subscript(pstate, subExpr); } else { -- 2.34.1