Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9915fe2

Browse files
committed
Document behavior of the .** jsonpath accessor in the lax mode
When the .** jsonpath accessor handles the array, it selects both array and each of its elements. When using lax mode, subsequent accessors automatically unwrap arrays. So, the content of each array element may be selected twice. Even though this behavior is counterintuitive, it's correct because everything works as designed. This commit documents it. Backpatch to 12 where the jsonpath language was introduced. Reported-by: Thomas Kellerer Bug: #16828 Discussion: https://postgr.es/m/16828-2b0229babfad2d8c%40postgresql.org Discussion: https://postgr.es/m/CAPpHfdtS-nNidT%3DEqZbAYOPcnNOWh_sd6skVdu2CAQUGdvpT8Q%40mail.gmail.com Author: Alexandex Korotkov, revised by Tom Lane Reviewed-by: Alvaro Herrera, Thomas Kellerer, Tom Lane Backpatch-through: 12
1 parent 4a9ce08 commit 9915fe2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc/src/sgml/func.sgml

+18
Original file line numberDiff line numberDiff line change
@@ -16257,6 +16257,24 @@ strict $.track.segments[*].location
1625716257
</programlisting>
1625816258
</para>
1625916259

16260+
<para>
16261+
The <literal>.**</literal> accessor can lead to surprising results
16262+
when using the lax mode. For instance, the following query selects every
16263+
<literal>HR</literal> value twice:
16264+
<programlisting>
16265+
lax $.**.HR
16266+
</programlisting>
16267+
This happens because the <literal>.**</literal> accessor selects both
16268+
the <literal>segments</literal> array and each of its elements, while
16269+
the <literal>.HR</literal> accessor automatically unwraps arrays when
16270+
using the lax mode. To avoid surprising results, we recommend using
16271+
the <literal>.**</literal> accessor only in the strict mode. The
16272+
following query selects each <literal>HR</literal> value just once:
16273+
<programlisting>
16274+
strict $.**.HR
16275+
</programlisting>
16276+
</para>
16277+
1626016278
</sect3>
1626116279

1626216280
<sect3 id="functions-sqljson-path-operators">

0 commit comments

Comments
 (0)