diff options
author | Amit Langote | 2024-04-18 05:33:47 +0000 |
---|---|---|
committer | Amit Langote | 2024-04-18 05:45:48 +0000 |
commit | b4fad46b6bc8a9bf46ff689bcb1bd4edf8f267af (patch) | |
tree | 48accd814bfb6c712699b8f26734fbf06c949b3e /src/backend/executor/execExprInterp.c | |
parent | 40126ac68f2ff96351cd6071350eb2d5cbd50145 (diff) |
SQL/JSON: Improve some error messages
This improves some error messages emitted by SQL/JSON query functions
by mentioning column name when available, such as when they are
invoked as part of evaluating JSON_TABLE() columns. To do so, a new
field column_name is added to both JsonFuncExpr and JsonExpr that is
only populated when creating those nodes for transformed JSON_TABLE()
columns.
While at it, relevant error messages are reworded for clarity.
Reported-by: Jian He <[email protected]>
Suggested-by: Jian He <[email protected]>
Discussion: https://postgr.es/m/CACJufxG_e0QLCgaELrr2ZNz7AxPeGCNKAORe3fHtFCQLsH4J4Q@mail.gmail.com
Diffstat (limited to 'src/backend/executor/execExprInterp.c')
-rw-r--r-- | src/backend/executor/execExprInterp.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 41af28cb1eb..852186312c5 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -4312,7 +4312,8 @@ ExecEvalJsonExprPath(ExprState *state, ExprEvalStep *op, case JSON_QUERY_OP: *op->resvalue = JsonPathQuery(item, path, jsexpr->wrapper, &empty, !throw_error ? &error : NULL, - jsestate->args); + jsestate->args, + jsexpr->column_name); *op->resnull = (DatumGetPointer(*op->resvalue) == NULL); @@ -4337,7 +4338,8 @@ ExecEvalJsonExprPath(ExprState *state, ExprEvalStep *op, { JsonbValue *jbv = JsonPathValue(item, path, &empty, !throw_error ? &error : NULL, - jsestate->args); + jsestate->args, + jsexpr->column_name); if (jbv == NULL) { @@ -4407,30 +4409,33 @@ ExecEvalJsonExprPath(ExprState *state, ExprEvalStep *op, /* Handle ON EMPTY. */ if (empty) { + *op->resvalue = (Datum) 0; + *op->resnull = true; if (jsexpr->on_empty) { - if (jsexpr->on_empty->btype == JSON_BEHAVIOR_ERROR) - ereport(ERROR, - errcode(ERRCODE_NO_SQL_JSON_ITEM), - errmsg("no SQL/JSON item")); - else + if (jsexpr->on_empty->btype != JSON_BEHAVIOR_ERROR) + { jsestate->empty.value = BoolGetDatum(true); - - Assert(jsestate->jump_empty >= 0); - return jsestate->jump_empty; + Assert(jsestate->jump_empty >= 0); + return jsestate->jump_empty; + } + } + else if (jsexpr->on_error->btype != JSON_BEHAVIOR_ERROR) + { + jsestate->error.value = BoolGetDatum(true); + Assert(!throw_error && jsestate->jump_error >= 0); + return jsestate->jump_error; } - else if (jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR) + + if (jsexpr->column_name) ereport(ERROR, errcode(ERRCODE_NO_SQL_JSON_ITEM), - errmsg("no SQL/JSON item")); + errmsg("no SQL/JSON item found for specified path of column \"%s\"", + jsexpr->column_name)); else - jsestate->error.value = BoolGetDatum(true); - - *op->resvalue = (Datum) 0; - *op->resnull = true; - - Assert(!throw_error && jsestate->jump_error >= 0); - return jsestate->jump_error; + ereport(ERROR, + errcode(ERRCODE_NO_SQL_JSON_ITEM), + errmsg("no SQL/JSON item found for specified path")); } /* |