[Minor] Possible missing syntax
Thread notes
1 note#docs
hackorum-bot#docs
@global #docs
In https://www.postgresql.org/docs/18/datatype-json.html#JSONB-SUBSCRIPTING
a row of the table says:
"
[subscript, ...]
Array element accessor. subscript can be given in two forms: index or
start_index to end_index. The first form returns a single array element by
its index. The second form returns an array slice by the range of indexes,
including the elements that correspond to the provided start_index and
end_index.
"
I infer from "[subscript, ...]" that several items can be specified. How
the range is specified is not clear to me since it can't be a comma as it
is the delimiter of arguments and something like "index_start to index_end"
("[2 to 3, 5 to 6]") seems unlikely.
I tried to find how it works in the source code but couldn't since I'm not
versed in C. If someone can find it and provide a clarification, I'll be
glad to propose a patch for it.
Thanks,
Rodrigo
On Thu, Oct 15, 2026 at 9:12 AM Matemática A3K <matematica.a3k@gmail.com>
wrote:
and something like "index_start to index_end" ("[2 to 3, 5 to 6]") seems
unlikely.
The row in question is technically correct.
SELECT jsonb_path_query_array(
'[10,20,30,40,50,60]'::jsonb,
'$[1 to 2, 4 to 5]'
) AS result;
[20, 30, 50, 60]
I'll agree the entire section could stand to use examples, like the ones
preceding it.
I'd probably also do:
[{index | start_index to end_index}}, ...]
Instead of leaving the inner syntax available only in the prose.
Or, taking the first and prior rows as multi-syntax examples:
[index, ...]
[start_index to end_index, ...]
And tweak the description accordingly.
David J.
On Thu, Oct 15, 2026 at 1:37 PM David G. Johnston <
david.g.johnston@gmail.com> wrote:
On Thu, Oct 15, 2026 at 9:12 AM Matemática A3K <matematica.a3k@gmail.com>
wrote:and something like "index_start to index_end" ("[2 to 3, 5 to 6]") seems
unlikely.The row in question is technically correct.
SELECT jsonb_path_query_array(
'[10,20,30,40,50,60]'::jsonb,
'$[1 to 2, 4 to 5]'
) AS result;[20, 30, 50, 60]
Indeed, thanks for the clarification!
I'll agree the entire section could stand to use examples, like the ones
preceding it.
I'd probably also do:
[{index | start_index to end_index}}, ...]
Instead of leaving the inner syntax available only in the prose.
I think this is the best solution. When preparing the patch, I realized
that the markup
in the source of the docs is clear:
"
It can be given in two forms:
<literal><replaceable>index</replaceable></literal>
or <literal><replaceable>start_index</replaceable> to
<replaceable>end_index</replaceable></literal>.
"
My confusion arose because of how the <literal> is rendered in this context
in HTML.
I find it hard to distinguish the prose from it, I haven't found a way of
changing it and arguing for that change
seems hard because it's entirely subjective on your vision (however, if you
share this concern I can dig further
and ask for help in the docbook community).
Given this, I find this change to better align the row with the others, so
I am attaching a patch.
On Fri, Oct 16, 2026 at 6:32 AM Matemática A3K <matematica.a3k@gmail.com>
wrote:
Given this, I find this change to better align the row with the others, so
I am attaching a patch.
You forgot to attempt a final build before submitting since you are missing
the closing literal tag on the synopsis.
You also left an extra } there.
Once you removed subscript the wording of the existing text, the "...can be
given in two forms:", is no longer is correct - the accessor requires the
brackets where the forms of subscript did not.
David J.
P.S. I do find the chosen background highlighting in light mode for
literal, light grey on white, to be insufficiently contrasted. Though in
this specific case the bold font face from replaceable would seem to more
than compensate for the deficiencies of literal. Though I do notice we do
seem to have different behaviors on these when they appear inside and
outside of a table, which seems problematic but, also, maybe necessary. In
short, research and changes in this area are possible though likely
nontrivial to derive and get committed.
On Fri, Oct 16, 2026 at 12:58 PM David G. Johnston <
david.g.johnston@gmail.com> wrote:
On Fri, Oct 16, 2026 at 6:32 AM Matemática A3K <matematica.a3k@gmail.com>
wrote:Given this, I find this change to better align the row with the others,
so I am attaching a patch.You forgot to attempt a final build before submitting since you are
missing the closing literal tag on the synopsis.
Yes, indeed, thanks, make check spotted it
You also left an extra } there.
Once you removed subscript the wording of the existing text, the "...can
be given in two forms:", is no longer is correct - the accessor requires
the brackets where the forms of subscript did not.
After fixing, this "reads right":
[{<literal><replaceable>index</replaceable></literal> |
<literal><replaceable>start_index</replaceable> to
<replaceable>end_index</replaceable></literal>}, ...]
but it is not clear that the curly braces and the "or" are not part of the
syntax, while the brackets are. How can this be stated? Is this what you
referred with "the accessor requires the brackets where the forms of
subscript did not"?
David J.
P.S. I do find the chosen background highlighting in light mode for
literal, light grey on white, to be insufficiently contrasted. Though in
this specific case the bold font face from replaceable would seem to more
than compensate for the deficiencies of literal. Though I do notice we do
seem to have different behaviors on these when they appear inside and
outside of a table, which seems problematic but, also, maybe necessary. In
short, research and changes in this area are possible though likely
nontrivial to derive and get committed.
Thanks for the advice, I won't pursue this ATM as I find it is not clear
the costs / benefits ratio.
After fixing, this "reads right":
[{<literal><replaceable>index</replaceable></literal> | <literal><replaceable>start_index</replaceable> to <replaceable>end_index</replaceable></literal>}, ...]
but it is not clear that the curly braces and the "or" are not part of the syntax, while the brackets are. How can this be stated? Is this what you referred with "the accessor requires the brackets where the forms of subscript did not"?
Given the lack of symbols to express this synthetically, I think the
original way is more readable but not "complete" in description.
A more comprehensive description would be:
"
[subscript ...]
Array element accessor. subscript can be given in two forms: index or
start_index to end_index. The first form returns a single array
element by its index. The second form returns an array slice by the
range of indexes, including the elements that correspond to the
provided start_index and end_index.
Multiple subscripts are supported, provided that they are separated by a comma.
The specified index can be an integer, as well as an expression
returning a single numeric value, which is automatically cast to
integer. Index zero corresponds to the first array element. You can
also use the last keyword to denote the last array element, which is
useful for handling arrays of unknown length.
Indexes or range of indexes which do not correspond to the array's
length are silently ignored.
"
(note the removed comma from the syntax, only second and fourth
sentences are new)
Do you think it is better?
BUMP! :)
David - or anyone,
Can you review the attached patch with these changes?
Thanks!
Show quoted text
On Mon, Oct 19, 2026 at 9:49 AM Matemática A3K <matematica.a3k@gmail.com> wrote:
After fixing, this "reads right":
[{<literal><replaceable>index</replaceable></literal> | <literal><replaceable>start_index</replaceable> to <replaceable>end_index</replaceable></literal>}, ...]
but it is not clear that the curly braces and the "or" are not part of the syntax, while the brackets are. How can this be stated? Is this what you referred with "the accessor requires the brackets where the forms of subscript did not"?
Given the lack of symbols to express this synthetically, I think the
original way is more readable but not "complete" in description.A more comprehensive description would be:
"
[subscript ...]Array element accessor. subscript can be given in two forms: index or
start_index to end_index. The first form returns a single array
element by its index. The second form returns an array slice by the
range of indexes, including the elements that correspond to the
provided start_index and end_index.Multiple subscripts are supported, provided that they are separated by a comma.
The specified index can be an integer, as well as an expression
returning a single numeric value, which is automatically cast to
integer. Index zero corresponds to the first array element. You can
also use the last keyword to denote the last array element, which is
useful for handling arrays of unknown length.Indexes or range of indexes which do not correspond to the array's
length are silently ignored.
"
(note the removed comma from the syntax, only second and fourth
sentences are new)Do you think it is better?