@@ -18593,9 +18593,10 @@ FROM
18593
18593
18594
18594
<synopsis>
18595
18595
JSON_TABLE (
18596
- <replaceable>context_item</replaceable>, <replaceable>path_expression</replaceable> <optional> PASSING { <replaceable>value</replaceable> AS <replaceable>varname</replaceable> } <optional>, ...</optional> </optional>
18596
+ <replaceable>context_item</replaceable>, <replaceable>path_expression</replaceable> <optional> AS <replaceable>json_path_name</replaceable> </optional> <optional> PASSING { <replaceable>value</replaceable> AS <replaceable>varname</replaceable> } <optional>, ...</optional> </optional>
18597
18597
COLUMNS ( <replaceable class="parameter">json_table_column</replaceable> <optional>, ...</optional> )
18598
18598
<optional>
18599
+ PLAN ( <replaceable class="parameter">json_table_plan</replaceable> ) |
18599
18600
PLAN DEFAULT ( { INNER | OUTER } <optional> , { CROSS | UNION } </optional>
18600
18601
| { CROSS | UNION } <optional> , { INNER | OUTER } </optional> )
18601
18602
</optional>
@@ -18619,6 +18620,16 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
18619
18620
| NESTED PATH <replaceable>json_path_specification</replaceable> <optional> AS <replaceable>path_name</replaceable> </optional>
18620
18621
COLUMNS ( <replaceable>json_table_column</replaceable> <optional>, ...</optional> )
18621
18622
| <replaceable>name</replaceable> FOR ORDINALITY
18623
+ <phrase>
18624
+ <replaceable>json_table_plan</replaceable> is:
18625
+ </phrase>
18626
+ <replaceable>json_path_name</replaceable> <optional> { OUTER | INNER } <replaceable>json_table_plan_primary</replaceable> </optional>
18627
+ | <replaceable>json_table_plan_primary</replaceable> { UNION <replaceable>json_table_plan_primary</replaceable> } <optional>...</optional>
18628
+ | <replaceable>json_table_plan_primary</replaceable> { CROSS <replaceable>json_table_plan_primary</replaceable> } <optional>...</optional>
18629
+ <phrase>
18630
+ <replaceable>json_table_plan_primary</replaceable> is:
18631
+ </phrase>
18632
+ <replaceable>json_path_name</replaceable> | ( <replaceable>json_table_plan</replaceable> )
18622
18633
18623
18634
</synopsis>
18624
18635
@@ -18661,7 +18672,7 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
18661
18672
joined to the row that generated them, so you do not have to explicitly join
18662
18673
the constructed view with the original table holding <acronym>JSON</acronym>
18663
18674
data. Optionally, you can specify how to join the columns returned
18664
- by <literal>NESTED PATH</literal> using the <literal>PLAN DEFAULT </literal> clause.
18675
+ by <literal>NESTED PATH</literal> using the <literal>PLAN</literal> clause.
18665
18676
</para>
18666
18677
18667
18678
<para>
@@ -18846,7 +18857,7 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
18846
18857
</para>
18847
18858
18848
18859
<para>
18849
- You can use the <literal>PLAN DEFAULT </literal> clause to define how
18860
+ You can use the <literal>PLAN</literal> clause to define how
18850
18861
to join the columns returned by <replaceable>NESTED PATH</replaceable> clauses.
18851
18862
</para>
18852
18863
</listitem>
@@ -18873,18 +18884,31 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
18873
18884
18874
18885
<varlistentry>
18875
18886
<term>
18876
- <literal>PLAN DEFAULT ( <replaceable>option </replaceable> <optional>, ... </optional> ) </literal>
18887
+ <literal>AS <replaceable>json_path_name </replaceable></literal>
18877
18888
</term>
18878
18889
<listitem>
18879
- <para>
18880
- Defines how to join the data returned by <replaceable>NESTED PATH</replaceable>
18881
- clauses to the constructed view. The <literal>INNER</literal> and
18882
- <literal>OUTER</literal> options define the joining plan for parent/child
18883
- columns, while <literal>UNION</literal> and <literal>CROSS</literal>
18884
- affect the sibling columns. You can override the default plans for all
18885
- columns at once.
18886
- </para>
18887
18890
18891
+ <para>
18892
+ The optional <replaceable>json_path_name</replaceable> serves as an
18893
+ identifier of the provided <replaceable>json_path_specification</replaceable>.
18894
+ The path name must be unique and cannot coincide with column names.
18895
+ When using the <literal>PLAN</literal> clause, you must specify the names
18896
+ for all the paths, including the row pattern. Each path name can appear in
18897
+ the <literal>PLAN</literal> clause only once.
18898
+ </para>
18899
+ </listitem>
18900
+ </varlistentry>
18901
+
18902
+ <varlistentry>
18903
+ <term>
18904
+ <literal>PLAN ( <replaceable class="parameter">json_table_plan</replaceable> )</literal>
18905
+ </term>
18906
+ <listitem>
18907
+
18908
+ <para>
18909
+ Defines how to join the data returned by <replaceable>NESTED PATH</replaceable>
18910
+ clauses to the constructed view.
18911
+ </para>
18888
18912
<para>
18889
18913
To join columns with parent/child relationship, you can use:
18890
18914
</para>
@@ -18963,6 +18987,23 @@ where <replaceable class="parameter">json_table_column</replaceable> is:
18963
18987
18964
18988
</listitem>
18965
18989
</varlistentry>
18990
+
18991
+ <varlistentry>
18992
+ <term>
18993
+ <literal>PLAN DEFAULT ( <replaceable>option</replaceable> <optional>, ... </optional> )</literal>
18994
+ </term>
18995
+ <listitem>
18996
+ <para>
18997
+ Overrides the default joining plans. The <literal>INNER</literal> and
18998
+ <literal>OUTER</literal> options define the joining plan for parent/child
18999
+ columns, while <literal>UNION</literal> and <literal>CROSS</literal>
19000
+ affect the sibling columns. You can override the default plans for all columns at once.
19001
+ Even though the path names are not incuded into the <literal>PLAN DEFAULT</literal>
19002
+ clause, they must be provided for all the paths to conform to
19003
+ the SQL/JSON standard.
19004
+ </para>
19005
+ </listitem>
19006
+ </varlistentry>
18966
19007
</variablelist>
18967
19008
</sect5>
18968
19009
@@ -18994,9 +19035,35 @@ SELECT jt.* FROM
18994
19035
</screen>
18995
19036
</para>
18996
19037
18997
- </sect5>
18998
- </sect4>
18999
-
19038
+ <para>
19039
+ Find a director that has done films in two different genres:
19040
+ <screen>
19041
+ SELECT
19042
+ director1 AS director, title1, kind1, title2, kind2
19043
+ FROM
19044
+ my_films,
19045
+ JSON_TABLE ( js, '$.favorites' AS favs COLUMNS (
19046
+ NESTED PATH '$[*]' AS films1 COLUMNS (
19047
+ kind1 text PATH '$.kind',
19048
+ NESTED PATH '$.films[*]' AS film1 COLUMNS (
19049
+ title1 text PATH '$.title',
19050
+ director1 text PATH '$.director')
19051
+ ),
19052
+ NESTED PATH '$[*]' AS films2 COLUMNS (
19053
+ kind2 text PATH '$.kind',
19054
+ NESTED PATH '$.films[*]' AS film2 COLUMNS (
19055
+ title2 text PATH '$.title',
19056
+ director2 text PATH '$.director'
19057
+ )
19058
+ )
19059
+ )
19060
+ PLAN (favs OUTER ((films1 INNER film1) CROSS (films2 INNER film2)))
19061
+ ) AS jt
19062
+ WHERE kind1 > kind2 AND director1 = director2;
19063
+ </screen>
19064
+ </para>
19065
+ </sect5>
19066
+ </sect4>
19000
19067
</sect3>
19001
19068
19002
19069
<sect3 id="functions-sqljson-serializing">
0 commit comments