Op 25-03-2022 om 21:30 schreef Andrew Dunstan:
On 3/22/22 10:55, Daniel Gustafsson wrote:
On 22 Mar 2022, at 16:31, Andrew Dunstan <and...@dunslane.net> wrote:
I'm planning on pushing the functions patch set this week and json-table
next week.
My comments from 30827b3c-edf6-4d41-bbf1-298181874...@yesql.se are yet to be
addressed (or at all responded to) in this patchset. I'll paste the ones which
still apply to make it easier:
I think I have fixed all those. See attached. I haven't prepared a new
patch set for SQL/JSON functions because there's just one typo to fix,
but I won't forget it. Please let me know if there's anything else you see.
At this stage I think I have finished with the actual code, and I'm
concentrating on improving the docs a bit.
> [ v59 ]
FWIW, I went through func.sgml (of v59) once.
Erik Rijkers
--- doc/src/sgml/func.sgml.orig 2022-03-25 22:17:13.908660140 +0100
+++ doc/src/sgml/func.sgml 2022-03-26 12:08:46.593271826 +0100
@@ -17673,8 +17673,8 @@
<title>Description</title>
<para>
- <function>JSON</function> function generates a <acronym>JSON</acronym>
- from a text data.
+ The <function>JSON</function> function generates <acronym>JSON</acronym>
+ from text data.
</para>
</sect5>
@@ -17688,7 +17688,7 @@
<listitem>
<para>
String expression that provides the <acronym>JSON</acronym> text data.
- Accepted any character strings (<type>text</type>, <type>char</type>, etc.)
+ Accepts any character strings (<type>text</type>, <type>char</type>, etc.)
or binary strings (<type>bytea</type>) in UTF8 encoding.
For null input, <acronym>SQL</acronym> null value is returned.
</para>
@@ -17757,7 +17757,7 @@
<sect5>
<title>Examples</title>
<para>
- Construct a JSON the provided strings:
+ Construct JSON using the provided strings:
</para>
<screen>
SELECT JSON('{ "a" : 123, "b": [ true, "foo" ], "a" : "bar" }');
@@ -17794,8 +17794,8 @@
<title>Description</title>
<para>
- <function>JSON_SCALAR</function> function generates a scalar
- <acronym>JSON</acronym> from a <acronym>SQL</acronym> data.
+ The <function>JSON_SCALAR</function> function generates scalar
+ <acronym>JSON</acronym> from <acronym>SQL</acronym> data.
</para>
</sect5>
@@ -17808,11 +17808,11 @@
</term>
<listitem>
<para>
- Expression that provides the data for constructing a
+ Expression that provides the data for constructing
<acronym>JSON</acronym>.
For null input, <acronym>SQL</acronym> null
- (not a <acronym>JSON</acronym> null) value is returned.
- For any scalar other than a number, a Boolean, the text representation
+ (not <acronym>JSON</acronym> null) value is returned.
+ For any scalar other than a number or a Boolean, the text representation
will be used, with escaping as necessary to make it a valid
<acronym>JSON</acronym> string value.
For details, see
@@ -17847,7 +17847,7 @@
<sect5>
<title>Examples</title>
<para>
- Construct a JSON from the provided values various types:
+ Construct JSON from provided values of various type:
</para>
<screen>
SELECT JSON_SCALAR(123.45);
@@ -18753,7 +18753,7 @@
<screen>
-- Strict mode with ERROR on ERROR clause
SELECT JSON_EXISTS(jsonb '{"a": [1,2,3]}', 'strict $.a[5]' ERROR ON ERROR);
-ERROR: Invalid SQL/JSON subscript
+ERROR: jsonpath array subscript is out of bounds
(1 row)
</screen>
@@ -18795,11 +18795,11 @@
<title>Description</title>
<para>
- <function>JSON_VALUE</function> function extracts a value from the provided
+ The <function>JSON_VALUE</function> function extracts a value from the provided
<acronym>JSON</acronym> data and converts it to an <acronym>SQL</acronym> scalar.
If the specified JSON path expression returns more than one
<acronym>SQL/JSON</acronym> item, an error occurs. To extract
- an <acronym>SQL/JSON</acronym> array or object, use <xref linkend="functions-jsonquery"/>.
+ an <acronym>SQL/JSON</acronym> array or object, see <xref linkend="functions-jsonquery"/>.
</para>
</sect5>
@@ -18885,19 +18885,19 @@
</para>
<screen>
-SELECT JSON_VALUE('"123.45"', '$' RETURNING float);
+SELECT JSON_VALUE('"123.45"'::jsonb, '$' RETURNING float);
json_value
------------
123.45
(1 row)
-SELECT JSON_VALUE('123.45', '$' RETURNING int ERROR ON ERROR);
+SELECT JSON_VALUE('123.45'::jsonb, '$' RETURNING int ERROR ON ERROR);
json_value
------------
123
(1 row)
-SELECT JSON_VALUE('"03:04 2015-02-01"', '$.datetime("HH24:MI YYYY-MM-DD")' RETURNING date);
+SELECT JSON_VALUE('"03:04 2015-02-01"'::jsonb, '$.datetime("HH24:MI YYYY-MM-DD")' RETURNING date);
json_value
------------
2015-02-01
@@ -18907,10 +18907,10 @@
ERROR: invalid input syntax for integer: "123.45"
SELECT JSON_VALUE(jsonb '[1]', 'strict $' ERROR ON ERROR);
-ERROR: SQL/JSON scalar required
+ERROR: JSON path expression in JSON_VALUE should return singleton scalar item
SELECT JSON_VALUE(jsonb '[1,2]', 'strict $[*]' ERROR ON ERROR);
-ERROR: more than one SQL/JSON item
+ERROR: JSON path expression in JSON_VALUE should return singleton scalar item
</screen>
<para>
@@ -18920,13 +18920,13 @@
</para>
<screen>
SELECT JSON_VALUE(jsonb '[1]', 'strict $' ERROR ON ERROR);
-ERROR: SQL/JSON scalar required
+ERROR: JSON path expression in JSON_VALUE should return singleton scalar item
SELECT JSON_VALUE(jsonb '{"a": 1}', 'strict $' ERROR ON ERROR);
-ERROR: SQL/JSON scalar required
+ERROR: JSON path expression in JSON_VALUE should return singleton scalar item
SELECT JSON_VALUE(jsonb '[1,2]', 'strict $[*]' ERROR ON ERROR);
-ERROR: more than one SQL/JSON item
+ERROR: JSON path expression in JSON_VALUE should return singleton scalar item
SELECT JSON_VALUE(jsonb '[1,2]', 'strict $[*]' DEFAULT 1 ON ERROR);
1
@@ -18954,11 +18954,11 @@
<title>Description</title>
<para>
- <function>JSON_QUERY</function> function extracts an <acronym>SQL/JSON</acronym>
+ The <function>JSON_QUERY</function> function extracts an <acronym>SQL/JSON</acronym>
array or object from <acronym>JSON</acronym> data. This function must return
a JSON string, so if the path expression returns a scalar or multiple SQL/JSON
items, you must wrap the result using the <literal>WITH WRAPPER</literal> clause.
- To extract a single <acronym>SQL/JSON</acronym> value, you can use <xref linkend="functions-jsonvalue"/>.
+ To extract a single <acronym>SQL/JSON</acronym> value, see JSON_VALUE (<xref linkend="functions-jsonvalue"/>).
</para>
</sect5>
@@ -19119,7 +19119,8 @@
SELECT
JSON_QUERY(js, '$.favorites[*].kind' ERROR ON ERROR)
FROM my_films;
-ERROR: more than one SQL/JSON item
+ERROR: JSON path expression in JSON_QUERY should return singleton item without wrapper
+HINT: use WITH WRAPPER clause to wrap SQL/JSON item sequence into array
</screen>
<para>