Skip to content

Commit eb49cad

Browse files
author
Nikita Glukhov
committed
Add documentation for JSON_TABLE PLAN clause
1 parent 162a4c2 commit eb49cad

File tree

1 file changed

+82
-15
lines changed

1 file changed

+82
-15
lines changed

doc/src/sgml/func.sgml

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18593,9 +18593,10 @@ FROM
1859318593

1859418594
1859518595
JSON_TABLE (
18596-
context_item, path_expression PASSING { value AS varname } , ...
18596+
context_item, path_expression AS json_path_name PASSING { value AS varname } , ...
1859718597
COLUMNS ( json_table_column , ... )
1859818598
18599+
PLAN ( json_table_plan ) |
1859918600
PLAN DEFAULT ( { INNER | OUTER } , { CROSS | UNION }
1860018601
| { CROSS | UNION } , { INNER | OUTER } )
1860118602
@@ -18619,6 +18620,16 @@ where json_table_column is:
1861918620
| NESTED PATH json_path_specification AS path_name
1862018621
COLUMNS ( json_table_column , ... )
1862118622
| name FOR ORDINALITY
18623+
18624+
json_table_plan is:
18625+
18626+
json_path_name { OUTER | INNER } json_table_plan_primary
18627+
| json_table_plan_primary { UNION json_table_plan_primary } ...
18628+
| json_table_plan_primary { CROSS json_table_plan_primary } ...
18629+
18630+
json_table_plan_primary is:
18631+
18632+
json_path_name | ( json_table_plan )
1862218633

1862318634
1862418635

@@ -18661,7 +18672,7 @@ where json_table_column is:
1866118672
joined to the row that generated them, so you do not have to explicitly join
1866218673
the constructed view with the original table holding JSON
1866318674
data. Optionally, you can specify how to join the columns returned
18664-
by NESTED PATH using the PLAN DEFAULT clause.
18675+
by NESTED PATH using the PLAN clause.
1866518676
1866618677

1866718678
@@ -18846,7 +18857,7 @@ where json_table_column is:
1884618857
1884718858

1884818859
18849-
You can use the PLAN DEFAULT clause to define how
18860+
You can use the PLAN clause to define how
1885018861
to join the columns returned by NESTED PATH clauses.
1885118862
1885218863
@@ -18873,18 +18884,31 @@ where json_table_column is:
1887318884

1887418885
1887518886
18876-
PLAN DEFAULT ( option , ... )
18887+
AS json_path_name
1887718888
1887818889
18879-
18880-
Defines how to join the data returned by NESTED PATH
18881-
clauses to the constructed view. The INNER and
18882-
OUTER options define the joining plan for parent/child
18883-
columns, while UNION and CROSS
18884-
affect the sibling columns. You can override the default plans for all
18885-
columns at once.
18886-
1888718890

18891+
18892+
The optional json_path_name serves as an
18893+
identifier of the provided json_path_specification.
18894+
The path name must be unique and cannot coincide with column names.
18895+
When using the PLAN clause, you must specify the names
18896+
for all the paths, including the row pattern. Each path name can appear in
18897+
the PLAN clause only once.
18898+
18899+
18900+
18901+
18902+
18903+
18904+
PLAN ( json_table_plan )
18905+
18906+
18907+
18908+
18909+
Defines how to join the data returned by NESTED PATH
18910+
clauses to the constructed view.
18911+
1888818912
1888918913
To join columns with parent/child relationship, you can use:
1889018914
@@ -18963,6 +18987,23 @@ where json_table_column is:
1896318987

1896418988
1896518989
18990+
18991+
18992+
18993+
PLAN DEFAULT ( option , ... )
18994+
18995+
18996+
18997+
Overrides the default joining plans. The INNER and
18998+
OUTER options define the joining plan for parent/child
18999+
columns, while UNION and CROSS
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 PLAN DEFAULT
19002+
clause, they must be provided for all the paths to conform to
19003+
the SQL/JSON standard.
19004+
19005+
19006+
1896619007
1896719008
1896819009

@@ -18994,9 +19035,35 @@ SELECT jt.* FROM
1899419035
1899519036
1899619037

18997-
18998-
18999-
19038+
19039+
Find a director that has done films in two different genres:
19040+
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+
19064+
19065+
19066+
1900019067
1900119068

1900219069

0 commit comments

Comments
 (0)