From e0a1bc8fb79d7d9f16aeb7280d1e1ae8af480d7d Mon Sep 17 00:00:00 2001 From: jian he Date: Mon, 11 Mar 2024 17:03:06 +0800 Subject: [PATCH v42 1/1] miscellaneous fix based on v42. type cast enum to int, before print out. minor refactor ExecPrepareJsonItemCoercion, to make the error message more explicit. --- src/backend/executor/execExprInterp.c | 8 +++++--- src/backend/parser/parse_expr.c | 2 +- src/backend/utils/adt/jsonb.c | 2 +- src/backend/utils/adt/jsonpath_exec.c | 2 +- src/backend/utils/adt/ruleutils.c | 2 +- src/test/regress/expected/sqljson_queryfuncs.out | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index decf8566..122efea0 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -4341,7 +4341,7 @@ ExecEvalJsonExprPath(ExprState *state, ExprEvalStep *op, } default: - elog(ERROR, "unrecognized SQL/JSON expression op %d", jexpr->op); + elog(ERROR, "unrecognized SQL/JSON expression op %d", (int) jexpr->op); return false; } @@ -4489,7 +4489,7 @@ ExecPrepareJsonItemCoercion(JsonbValue *item, JsonExprState *jsestate, break; default: - elog(ERROR, "unexpected jsonb value type %d", item->type); + elog(ERROR, "unexpected jsonb value type %d", (int) item->type); } /* If the expression is not a cast expression, throw an error. */ @@ -4498,7 +4498,9 @@ ExecPrepareJsonItemCoercion(JsonbValue *item, JsonExprState *jsestate, if (throw_error) ereport(ERROR, errcode(ERRCODE_SQL_JSON_ITEM_CANNOT_BE_CAST_TO_TARGET_TYPE), - errmsg("SQL/JSON item cannot be cast to target type")); + errcode(ERRCODE_SQL_JSON_ITEM_CANNOT_BE_CAST_TO_TARGET_TYPE), + errmsg("SQL/JSON item cannot be cast to type %s", + format_type_be(jsestate->jsexpr->returning->typid))); *resvalue = (Datum) 0; *resnull = true; diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 53426fac..5610608b 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -4706,7 +4706,7 @@ GetJsonBehaviorConstExpr(JsonBehaviorType btype, int location) break; default: - elog(ERROR, "unrecognized SQL/JSON behavior %d", btype); + elog(ERROR, "unrecognized SQL/JSON behavior %d", (int) btype); break; } diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c index 8ffa26b7..a8cf307d 100644 --- a/src/backend/utils/adt/jsonb.c +++ b/src/backend/utils/adt/jsonb.c @@ -2183,7 +2183,7 @@ JsonbUnquote(Jsonb *jb) return pstrdup("null"); else { - elog(ERROR, "unrecognized jsonb value type %d", v.type); + elog(ERROR, "unrecognized jsonb value type %d", (int) v.type); return NULL; } } diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index 1d2d0245..7400a440 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -3818,7 +3818,7 @@ JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, JsonContainerIsScalar(singleton->val.binary.data)); else { - elog(ERROR, "unrecognized json wrapper %d", wrapper); + elog(ERROR, "unrecognized json wrapper %d", (int) wrapper); wrap = false; } diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index a38be6fb..16b50c5b 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -8613,7 +8613,7 @@ get_json_behavior(JsonBehavior *behavior, deparse_context *context, }; if ((int) behavior->btype < 0 || behavior->btype >= lengthof(behavior_names)) - elog(ERROR, "invalid json behavior type: %d", behavior->btype); + elog(ERROR, "invalid json behavior type: %d", (int) behavior->btype); appendStringInfoString(context->buf, behavior_names[behavior->btype]); diff --git a/src/test/regress/expected/sqljson_queryfuncs.out b/src/test/regress/expected/sqljson_queryfuncs.out index f5b57465..b7b7d33e 100644 --- a/src/test/regress/expected/sqljson_queryfuncs.out +++ b/src/test/regress/expected/sqljson_queryfuncs.out @@ -203,7 +203,7 @@ SELECT JSON_VALUE(jsonb '123', '$' RETURNING text); /* jsonb bytea ??? */ SELECT JSON_VALUE(jsonb '123', '$' RETURNING bytea ERROR ON ERROR); -ERROR: SQL/JSON item cannot be cast to target type +ERROR: SQL/JSON item cannot be cast to type bytea SELECT JSON_VALUE(jsonb '1.23', '$'); json_value ------------ -- 2.34.1