Skip to content

Commit ef744eb

Browse files
committed
SQL/JSON: Miscellaneous fixes and improvements
This addresses some post-commit review comments for commits 6185c97, de36004, 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
1 parent c0fc075 commit ef744eb

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

doc/src/sgml/func.sgml

+5-4
Original file line numberDiff line numberDiff line change
@@ -18942,7 +18942,7 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
1894218942
<optional> { ERROR | NULL | EMPTY { ARRAY | OBJECT } | DEFAULT <replaceable>expression</replaceable> } ON ERROR </optional>
1894318943
| <replaceable>name</replaceable> <replaceable>type</replaceable> EXISTS <optional> PATH <replaceable>path_expression</replaceable> </optional>
1894418944
<optional> { ERROR | TRUE | FALSE | UNKNOWN } ON ERROR </optional>
18945-
| 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> )
18945+
| NESTED <optional> PATH </optional> <replaceable>path_expression</replaceable> <optional> AS <replaceable>json_path_name</replaceable> </optional> COLUMNS ( <replaceable>json_table_column</replaceable> <optional>, ...</optional> )
1894618946
</synopsis>
1894718947

1894818948
<para>
@@ -19083,7 +19083,7 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
1908319083

1908419084
<varlistentry>
1908519085
<term>
19086-
<literal>NESTED <optional> PATH </optional></literal> <replaceable>json_path_specification</replaceable> <optional> <literal>AS</literal> <replaceable>json_path_name</replaceable> </optional>
19086+
<literal>NESTED <optional> PATH </optional></literal> <replaceable>path_expression</replaceable> <optional> <literal>AS</literal> <replaceable>json_path_name</replaceable> </optional>
1908719087
<literal>COLUMNS</literal> ( <replaceable>json_table_column</replaceable> <optional>, ...</optional> )
1908819088
</term>
1908919089
<listitem>
@@ -19315,8 +19315,9 @@ SELECT * FROM JSON_TABLE (
1931519315
"books":
1931619316
[{"name": "Mystery", "authors": [{"name": "Brown Dan"}]},
1931719317
{"name": "Wonder", "authors": [{"name": "Jun Murakami"}, {"name":"Craig Doe"}]}]
19318-
}}'::json, '$.favs[*]'
19319-
COLUMNS (user_id FOR ORDINALITY,
19318+
}}'::json, '$.favorites[*]'
19319+
COLUMNS (
19320+
user_id FOR ORDINALITY,
1932019321
NESTED '$.movies[*]'
1932119322
COLUMNS (
1932219323
movie_id FOR ORDINALITY,

src/backend/utils/adt/jsonpath_exec.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3935,7 +3935,7 @@ JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty,
39353935
JsonContainerIsScalar(singleton->val.binary.data));
39363936
else
39373937
{
3938-
elog(ERROR, "unrecognized json wrapper %d", wrapper);
3938+
elog(ERROR, "unrecognized json wrapper %d", (int) wrapper);
39393939
wrap = false;
39403940
}
39413941

src/include/utils/jsonpath.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,9 @@ extern JsonPathParseResult *parsejsonpath(const char *str, int len,
281281
extern bool jspConvertRegexFlags(uint32 xflags, int *result,
282282
struct Node *escontext);
283283

284-
285284
/*
286-
* Evaluation of jsonpath
285+
* Struct for details about external variables passed into jsonpath executor
287286
*/
288-
289-
/* External variable passed into jsonpath. */
290287
typedef struct JsonPathVariable
291288
{
292289
char *name;
@@ -297,7 +294,7 @@ typedef struct JsonPathVariable
297294
} JsonPathVariable;
298295

299296

300-
/* SQL/JSON item */
297+
/* SQL/JSON query functions */
301298
extern bool JsonPathExists(Datum jb, JsonPath *path, bool *error, List *vars);
302299
extern Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper,
303300
bool *empty, bool *error, List *vars,
@@ -306,6 +303,7 @@ extern JsonbValue *JsonPathValue(Datum jb, JsonPath *jp, bool *empty,
306303
bool *error, List *vars,
307304
const char *column_name);
308305

306+
/* For JSON_TABLE() */
309307
extern PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine;
310308

311309
#endif

0 commit comments

Comments
 (0)