@@ -2286,19 +2286,84 @@ impl fmt::Display for ForJson {
22862286}
22872287
22882288/// A single column definition in MySQL's `JSON_TABLE` table valued function.
2289+ ///
2290+ /// See
2291+ /// - [MySQL's JSON_TABLE documentation](https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html#function_json-table)
2292+ /// - [Oracle's JSON_TABLE documentation](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/JSON_TABLE.html)
2293+ /// - [MariaDB's JSON_TABLE documentation](https://mariadb.com/kb/en/json_table/)
2294+ ///
22892295/// ```sql
22902296/// SELECT *
22912297/// FROM JSON_TABLE(
22922298/// '["a", "b"]',
22932299/// '$[*]' COLUMNS (
2294- /// value VARCHAR(20) PATH '$'
2300+ /// name FOR ORDINALITY,
2301+ /// value VARCHAR(20) PATH '$',
2302+ /// NESTED PATH '$[*]' COLUMNS (
2303+ /// value VARCHAR(20) PATH '$'
2304+ /// )
22952305/// )
22962306/// ) AS jt;
22972307/// ```
22982308#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
22992309#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
23002310#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2301- pub struct JsonTableColumn {
2311+ pub enum JsonTableColumn {
2312+ /// A named column with a JSON path
2313+ Named ( JsonTableNamedColumn ) ,
2314+ /// The FOR ORDINALITY column, which is a special column that returns the index of the current row in a JSON array.
2315+ ForOrdinality ( Ident ) ,
2316+ /// A set of nested columns, which extracts data from a nested JSON array.
2317+ Nested ( JsonTableNestedColumn ) ,
2318+ }
2319+
2320+ impl fmt:: Display for JsonTableColumn {
2321+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2322+ match self {
2323+ JsonTableColumn :: Named ( json_table_named_column) => {
2324+ write ! ( f, "{json_table_named_column}" )
2325+ }
2326+ JsonTableColumn :: ForOrdinality ( ident) => write ! ( f, "{} FOR ORDINALITY" , ident) ,
2327+ JsonTableColumn :: Nested ( json_table_nested_column) => {
2328+ write ! ( f, "{json_table_nested_column}" )
2329+ }
2330+ }
2331+ }
2332+ }
2333+
2334+ /// A nested column in a JSON_TABLE column list
2335+ ///
2336+ /// See <https://mariadb.com/kb/en/json_table/#nested-paths>
2337+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2338+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2339+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2340+ pub struct JsonTableNestedColumn {
2341+ pub path : Value ,
2342+ pub columns : Vec < JsonTableColumn > ,
2343+ }
2344+
2345+ impl fmt:: Display for JsonTableNestedColumn {
2346+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2347+ write ! (
2348+ f,
2349+ "NESTED PATH {} COLUMNS ({})" ,
2350+ self . path,
2351+ display_comma_separated( & self . columns)
2352+ )
2353+ }
2354+ }
2355+
2356+ /// A single column definition in MySQL's `JSON_TABLE` table valued function.
2357+ ///
2358+ /// See <https://mariadb.com/kb/en/json_table/#path-columns>
2359+ ///
2360+ /// ```sql
2361+ /// value VARCHAR(20) PATH '$'
2362+ /// ```
2363+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2364+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2365+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2366+ pub struct JsonTableNamedColumn {
23022367 /// The name of the column to be extracted.
23032368 pub name : Ident ,
23042369 /// The type of the column to be extracted.
@@ -2313,7 +2378,7 @@ pub struct JsonTableColumn {
23132378 pub on_error : Option < JsonTableColumnErrorHandling > ,
23142379}
23152380
2316- impl fmt:: Display for JsonTableColumn {
2381+ impl fmt:: Display for JsonTableNamedColumn {
23172382 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
23182383 write ! (
23192384 f,
0 commit comments