diff options
author | Amit Langote <amitlan@postgresql.org> | 2024-04-18 14:33:47 +0900 |
---|---|---|
committer | Amit Langote <amitlan@postgresql.org> | 2024-04-18 14:45:48 +0900 |
commit | b4fad46b6bc8a9bf46ff689bcb1bd4edf8f267af (patch) | |
tree | 48accd814bfb6c712699b8f26734fbf06c949b3e /src/backend/parser/parse_jsontable.c | |
parent | 40126ac68f2ff96351cd6071350eb2d5cbd50145 (diff) | |
download | postgresql-b4fad46b6bc8a9bf46ff689bcb1bd4edf8f267af.tar.gz postgresql-b4fad46b6bc8a9bf46ff689bcb1bd4edf8f267af.zip |
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 <jian.universality@gmail.com>
Suggested-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxG_e0QLCgaELrr2ZNz7AxPeGCNKAORe3fHtFCQLsH4J4Q@mail.gmail.com
Diffstat (limited to 'src/backend/parser/parse_jsontable.c')
-rw-r--r-- | src/backend/parser/parse_jsontable.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/backend/parser/parse_jsontable.c b/src/backend/parser/parse_jsontable.c index 99d3101f6b2..37f2cba0ef0 100644 --- a/src/backend/parser/parse_jsontable.c +++ b/src/backend/parser/parse_jsontable.c @@ -402,12 +402,6 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr, Node *pathspec; JsonFuncExpr *jfexpr = makeNode(JsonFuncExpr); - /* - * XXX consider inventing JSON_TABLE_VALUE_OP, etc. and pass the column - * name via JsonExpr so that JsonPathValue(), etc. can provide error - * message tailored to JSON_TABLE(), such as by mentioning the column - * names in the message. - */ if (jtc->coltype == JTC_REGULAR) jfexpr->op = JSON_VALUE_OP; else if (jtc->coltype == JTC_EXISTS) @@ -415,6 +409,10 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr, else jfexpr->op = JSON_QUERY_OP; + /* Pass the column name so any runtime JsonExpr errors can print it. */ + Assert(jtc->name != NULL); + jfexpr->column_name = pstrdup(jtc->name); + jfexpr->context_item = makeJsonValueExpr((Expr *) contextItemExpr, NULL, makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, |