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/include | |
| 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 <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/include')
| -rw-r--r-- | src/include/nodes/parsenodes.h | 2 | ||||
| -rw-r--r-- | src/include/nodes/primnodes.h | 3 | ||||
| -rw-r--r-- | src/include/utils/jsonpath.h | 6 |
3 files changed, 9 insertions, 2 deletions
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 0cab8908437..c5f34efe271 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1791,6 +1791,8 @@ typedef struct JsonFuncExpr { NodeTag type; JsonExprOp op; /* expression type */ + char *column_name; /* JSON_TABLE() column name or NULL if this is + * not for a JSON_TABLE() */ JsonValueExpr *context_item; /* context item expression */ Node *pathspec; /* JSON path specification expression */ List *passing; /* list of PASSING clause arguments, if any */ diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 6b0172f4275..0052c1f0ee2 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -1782,6 +1782,9 @@ typedef struct JsonExpr JsonExprOp op; + char *column_name; /* JSON_TABLE() column name or NULL if this is + * not for a JSON_TABLE() */ + /* jsonb-valued expression to query */ Node *formatted_expr; diff --git a/src/include/utils/jsonpath.h b/src/include/utils/jsonpath.h index 4d3964488dd..0bcc1ac569d 100644 --- a/src/include/utils/jsonpath.h +++ b/src/include/utils/jsonpath.h @@ -300,9 +300,11 @@ typedef struct JsonPathVariable /* SQL/JSON item */ extern bool JsonPathExists(Datum jb, JsonPath *path, bool *error, List *vars); extern Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, - bool *empty, bool *error, List *vars); + bool *empty, bool *error, List *vars, + const char *column_name); extern JsonbValue *JsonPathValue(Datum jb, JsonPath *jp, bool *empty, - bool *error, List *vars); + bool *error, List *vars, + const char *column_name); extern PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine; |
