SQL/JSON: Document behavior when input document is not jsonb
authorAmit Langote <[email protected]>
Fri, 28 Jun 2024 00:42:13 +0000 (09:42 +0900)
committerAmit Langote <[email protected]>
Fri, 28 Jun 2024 00:45:03 +0000 (09:45 +0900)
The input document to functions JSON_EXISTS(), JSON_QUERY(),
JSON_VALUE(), and JSON_TABLE() can be specified as character or
UTF8-encoded bytea strings. These are automatically converted to
jsonb with an implicit cast before being passed to the jsonpath
machinery.

In the current implementation, errors that occur when parsing the
specified string into a valid JSON document are thrown
unconditionally. This means they are not subject to the explicit or
implicit ON ERROR clause of those functions, which is a standard-
conforming behavior.  Add a note to the documentation to mention
that.

Reported-by: Markus Winand
Discussion: https://postgr.es/m/F7DD1442-265C-4220-A603-CB0DEB77E91D%40winand.at

doc/src/sgml/func.sgml

index 2609269610b27e60876b9386442f1fa2036210ed..323098a237793b5b6360230404b67d6941a326c0 100644 (file)
@@ -18861,6 +18861,16 @@ DETAIL:  Missing "]" after array dimensions.
     </tbody>
    </tgroup>
   </table>
+  <note>
+   <para>
+    The <replaceable>context_item</replaceable> expression is converted to
+    <type>jsonb</type> by an implicit cast if the expression is not already of
+    type <type>jsonb</type>. Note, however, that any parsing errors that occur
+    during that conversion are thrown unconditionally, that is, are not
+    handled according to the (specified or implicit) <literal>ON ERROR</literal>
+    clause.
+   </para>
+  </note>
   </sect2>
 
  <sect2 id="functions-sqljson-table">