SQL/JSON: Miscellaneous fixes and improvements
authorAmit Langote
Thu, 18 Apr 2024 05:38:12 +0000 (14:38 +0900)
committerAmit Langote
Thu, 18 Apr 2024 05:46:43 +0000 (14:46 +0900)
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
Discussion: https://postgr.es/m/CACJufxG_e0QLCgaELrr2ZNz7AxPeGCNKAORe3fHtFCQLsH4J4Q@mail.gmail.com

doc/src/sgml/func.sgml
src/backend/utils/adt/jsonpath_exec.c
src/include/utils/jsonpath.h

index 8dfb42ad4db87e6418df8a1a4a6721dbf8ab9b43..92a0f49e6a15fe950856cd4509d0208681cc5e9b 100644 (file)
@@ -18942,7 +18942,7 @@ where json_table_column is:
          { ERROR | NULL | EMPTY { ARRAY | OBJECT } | DEFAULT expression } ON ERROR 
   | name type EXISTS  PATH path_expression 
          { ERROR | TRUE | FALSE | UNKNOWN } ON ERROR 
-  | NESTED  PATH  json_path_specification  AS json_path_name  COLUMNS ( json_table_column , ... )
+  | NESTED  PATH  path_expression  AS json_path_name  COLUMNS ( json_table_column , ... )
 
 
   
@@ -19083,7 +19083,7 @@ where json_table_column is:
 
    
     
-      NESTED  PATH  json_path_specification  AS json_path_name 
+      NESTED  PATH  path_expression  AS json_path_name 
           COLUMNS ( json_table_column , ... )
     
     
@@ -19315,8 +19315,9 @@ SELECT * FROM JSON_TABLE (
      "books":
       [{"name": "Mystery", "authors": [{"name": "Brown Dan"}]},
        {"name": "Wonder", "authors": [{"name": "Jun Murakami"}, {"name":"Craig Doe"}]}]
-}}'::json, '$.favs[*]'
-COLUMNS (user_id FOR ORDINALITY,
+}}'::json, '$.favorites[*]'
+COLUMNS (
+  user_id FOR ORDINALITY,
   NESTED '$.movies[*]'
     COLUMNS (
     movie_id FOR ORDINALITY,
index e74dc1b2d429733109fc5ff0fc7f68951aeddf68..4daf1a68d9de1232676b87d03e765656e7d696f6 100644 (file)
@@ -3935,7 +3935,7 @@ JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty,
             JsonContainerIsScalar(singleton->val.binary.data));
    else
    {
-       elog(ERROR, "unrecognized json wrapper %d", wrapper);
+       elog(ERROR, "unrecognized json wrapper %d", (int) wrapper);
        wrap = false;
    }
 
index 0bcc1ac569d9f65eb68bd2c3ec47c14a512eed56..69c180c2e29c353a0cdd886b5309c7c62888aa18 100644 (file)
@@ -281,12 +281,9 @@ extern JsonPathParseResult *parsejsonpath(const char *str, int len,
 extern bool jspConvertRegexFlags(uint32 xflags, int *result,
                                 struct Node *escontext);
 
-
 /*
- * Evaluation of jsonpath
+ * Struct for details about external variables passed into jsonpath executor
  */
-
-/* External variable passed into jsonpath. */
 typedef struct JsonPathVariable
 {
    char       *name;
@@ -297,7 +294,7 @@ typedef struct JsonPathVariable
 } JsonPathVariable;
 
 
-/* SQL/JSON item */
+/* SQL/JSON query functions */
 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,
@@ -306,6 +303,7 @@ extern JsonbValue *JsonPathValue(Datum jb, JsonPath *jp, bool *empty,
                                 bool *error, List *vars,
                                 const char *column_name);
 
+/* For JSON_TABLE() */
 extern PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine;
 
 #endif