SQL/JSON: Miscellaneous fixes and improvements

This addresses some post-commit review comments for commits 6185c973,
de3600452, and 9425c596a0, with the following changes:

* Fix JSON_TABLE() syntax documentation to use the term
  "path_expression" for JSON path expressions instead of
  "json_path_specification" to be consistent with the other SQL/JSON
  functions.

* Fix a typo in the example code in JSON_TABLE() documentation.

* Rewrite some newly added comments in jsonpath.h.

* In JsonPathQuery(), add missing cast to int before printing an enum
  value.

Reported-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxG_e0QLCgaELrr2ZNz7AxPeGCNKAORe3fHtFCQLsH4J4Q@mail.gmail.com
This commit is contained in:
Amit Langote 2024-04-18 14:38:12 +09:00
parent c0fc075186
commit ef744ebb73
3 changed files with 9 additions and 10 deletions

View File

@ -18942,7 +18942,7 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
<optional> { ERROR | NULL | EMPTY { ARRAY | OBJECT } | DEFAULT <replaceable>expression</replaceable> } ON ERROR </optional> <optional> { ERROR | NULL | EMPTY { ARRAY | OBJECT } | DEFAULT <replaceable>expression</replaceable> } ON ERROR </optional>
| <replaceable>name</replaceable> <replaceable>type</replaceable> EXISTS <optional> PATH <replaceable>path_expression</replaceable> </optional> | <replaceable>name</replaceable> <replaceable>type</replaceable> EXISTS <optional> PATH <replaceable>path_expression</replaceable> </optional>
<optional> { ERROR | TRUE | FALSE | UNKNOWN } ON ERROR </optional> <optional> { ERROR | TRUE | FALSE | UNKNOWN } ON ERROR </optional>
| NESTED <optional> PATH </optional> <replaceable>json_path_specification</replaceable> <optional> AS <replaceable>json_path_name</replaceable> </optional> COLUMNS ( <replaceable>json_table_column</replaceable> <optional>, ...</optional> ) | NESTED <optional> PATH </optional> <replaceable>path_expression</replaceable> <optional> AS <replaceable>json_path_name</replaceable> </optional> COLUMNS ( <replaceable>json_table_column</replaceable> <optional>, ...</optional> )
</synopsis> </synopsis>
<para> <para>
@ -19083,7 +19083,7 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
<varlistentry> <varlistentry>
<term> <term>
<literal>NESTED <optional> PATH </optional></literal> <replaceable>json_path_specification</replaceable> <optional> <literal>AS</literal> <replaceable>json_path_name</replaceable> </optional> <literal>NESTED <optional> PATH </optional></literal> <replaceable>path_expression</replaceable> <optional> <literal>AS</literal> <replaceable>json_path_name</replaceable> </optional>
<literal>COLUMNS</literal> ( <replaceable>json_table_column</replaceable> <optional>, ...</optional> ) <literal>COLUMNS</literal> ( <replaceable>json_table_column</replaceable> <optional>, ...</optional> )
</term> </term>
<listitem> <listitem>
@ -19315,8 +19315,9 @@ SELECT * FROM JSON_TABLE (
"books": "books":
[{"name": "Mystery", "authors": [{"name": "Brown Dan"}]}, [{"name": "Mystery", "authors": [{"name": "Brown Dan"}]},
{"name": "Wonder", "authors": [{"name": "Jun Murakami"}, {"name":"Craig Doe"}]}] {"name": "Wonder", "authors": [{"name": "Jun Murakami"}, {"name":"Craig Doe"}]}]
}}'::json, '$.favs[*]' }}'::json, '$.favorites[*]'
COLUMNS (user_id FOR ORDINALITY, COLUMNS (
user_id FOR ORDINALITY,
NESTED '$.movies[*]' NESTED '$.movies[*]'
COLUMNS ( COLUMNS (
movie_id FOR ORDINALITY, movie_id FOR ORDINALITY,

View File

@ -3935,7 +3935,7 @@ JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty,
JsonContainerIsScalar(singleton->val.binary.data)); JsonContainerIsScalar(singleton->val.binary.data));
else else
{ {
elog(ERROR, "unrecognized json wrapper %d", wrapper); elog(ERROR, "unrecognized json wrapper %d", (int) wrapper);
wrap = false; wrap = false;
} }

View File

@ -281,12 +281,9 @@ extern JsonPathParseResult *parsejsonpath(const char *str, int len,
extern bool jspConvertRegexFlags(uint32 xflags, int *result, extern bool jspConvertRegexFlags(uint32 xflags, int *result,
struct Node *escontext); struct Node *escontext);
/* /*
* Evaluation of jsonpath * Struct for details about external variables passed into jsonpath executor
*/ */
/* External variable passed into jsonpath. */
typedef struct JsonPathVariable typedef struct JsonPathVariable
{ {
char *name; char *name;
@ -297,7 +294,7 @@ typedef struct JsonPathVariable
} JsonPathVariable; } JsonPathVariable;
/* SQL/JSON item */ /* SQL/JSON query functions */
extern bool JsonPathExists(Datum jb, JsonPath *path, bool *error, List *vars); extern bool JsonPathExists(Datum jb, JsonPath *path, bool *error, List *vars);
extern Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, extern Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper,
bool *empty, bool *error, List *vars, bool *empty, bool *error, List *vars,
@ -306,6 +303,7 @@ extern JsonbValue *JsonPathValue(Datum jb, JsonPath *jp, bool *empty,
bool *error, List *vars, bool *error, List *vars,
const char *column_name); const char *column_name);
/* For JSON_TABLE() */
extern PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine; extern PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine;
#endif #endif