Re: Doc Rework: Section 9.16.13 SQL/JSON Query Functions

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Doc Rework: Section 9.16.13 SQL/JSON Query Functions
Date: 2024-07-04 09:16:00
Message-ID: CACJufxGjac8E7rUsUnRfyEWADXbEZGtxA1M1_5QkY98DFbf-6A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

still based on v2-0001, v2-0002.
picture attached.

as you can see from the curly braces,
```
{ KEEP | OMIT } QUOTES [ ON SCALAR STRING ]
```
we must choose one, "KEEP" or "OMIT".

but the wrapping_clause:
```
WITHOUT [ARRAY] WRAPPER
WITH [UNCONDITIONAL] [ARRAY] WRAPPER
WITH CONDITIONAL [ARRAY] WRAPPER
```
this way, didn't say we must choose between one in these three.
-----------
on_error_boolean
on_error_set
on_error_value
on_empty_set
on_empty_value

alternative ON { ERROR | EMPTY }

````
didn't explain on_error_value, on_empty_value.
why not just on_error_clause, on_empty_clause?

-------
<<<quoted paragraph
When JSON_QUERY function produces multiple JSON values, they are
returned as a JSON array. By default, the result values are
unconditionally wrapped even if the array contains only one element.
You can specify the WITH CONDITIONAL variant to say that the wrapper
be added only when there are multiple values in the resulting array.
Or specify the WITHOUT variant to say that the wrapper be removed when
there is only one element, but it is ignored if there are multiple
values.
<<<quoted paragraph

The above paragraph didn't explicitly mention that UNCONDITIONAL is the default.
BTW, by comparing patch with master, I found out:

"""
If the wrapper is UNCONDITIONAL, an array wrapper will always be
applied, even if the returned value is already a single JSON object or
an array. If it is CONDITIONAL, it will not be applied to a single
JSON object or an array. UNCONDITIONAL is the default.
"""
this description seems not right.
if "UNCONDITIONAL is the default", then
select json_query(jsonb '{"a": [1]}', 'lax $.a' with unconditional
array wrapper);
should be same as
select json_query(jsonb '{"a": [1]}', 'lax $.a' );

another two examples with SQL/JSON scalar item:

select json_query(jsonb '{"a": 1}', 'lax $.a' );
select json_query(jsonb '{"a": 1}', 'lax $.a' with unconditional wrapper);

Am I interpreting "UNCONDITIONAL is the default" the wrong way?

Attachment Content-Type Size
Screenshot from 2024-07-04 16-35-33.png image/png 422.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2024-07-04 09:17:41 Re: Support "Right Semi Join" plan shapes
Previous Message Aleksander Alekseev 2024-07-04 09:12:11 Re: PostgreSQL does not compile on macOS SDK 15.0