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

Commit bd63661

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 22f71a6 commit bd63661

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc/src/sgml/func.sgml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13149,6 +13149,24 @@ table2-mapping
1314913149
</programlisting>
1315013150
</para>
1315113151

13152+
<para>
13153+
The <literal>.**</literal> accessor can lead to surprising results
13154+
when using the lax mode. For instance, the following query selects every
13155+
<literal>HR</literal> value twice:
13156+
<programlisting>
13157+
lax $.**.HR
13158+
</programlisting>
13159+
This happens because the <literal>.**</literal> accessor selects both
13160+
the <literal>segments</literal> array and each of its elements, while
13161+
the <literal>.HR</literal> accessor automatically unwraps arrays when
13162+
using the lax mode. To avoid surprising results, we recommend using
13163+
the <literal>.**</literal> accessor only in the strict mode. The
13164+
following query selects each <literal>HR</literal> value just once:
13165+
<programlisting>
13166+
strict $.**.HR
13167+
</programlisting>
13168+
</para>
13169+
1315213170
</sect3>
1315313171

1315413172
<sect3 id="jsonpath-regular-expressions">

0 commit comments

Comments
 (0)