@@ -2773,41 +2773,45 @@ pub enum Statement {
2773
2773
/// ```sql
2774
2774
/// SHOW COLUMNS
2775
2775
/// ```
2776
- ///
2777
- /// Note: this is a MySQL-specific statement.
2778
2776
ShowColumns {
2779
2777
extended : bool ,
2780
2778
full : bool ,
2781
- #[ cfg_attr( feature = "visitor" , visit( with = "visit_relation" ) ) ]
2782
- table_name : ObjectName ,
2783
- filter : Option < ShowStatementFilter > ,
2779
+ show_options : ShowStatementOptions ,
2784
2780
} ,
2785
2781
/// ```sql
2786
- /// SHOW DATABASES [LIKE 'pattern']
2782
+ /// SHOW DATABASES
2787
2783
/// ```
2788
- ShowDatabases { filter : Option < ShowStatementFilter > } ,
2784
+ ShowDatabases {
2785
+ terse : bool ,
2786
+ history : bool ,
2787
+ show_options : ShowStatementOptions ,
2788
+ } ,
2789
2789
/// ```sql
2790
- /// SHOW SCHEMAS [LIKE 'pattern']
2790
+ /// SHOW SCHEMAS
2791
2791
/// ```
2792
- ShowSchemas { filter : Option < ShowStatementFilter > } ,
2792
+ ShowSchemas {
2793
+ terse : bool ,
2794
+ history : bool ,
2795
+ show_options : ShowStatementOptions ,
2796
+ } ,
2793
2797
/// ```sql
2794
2798
/// SHOW TABLES
2795
2799
/// ```
2796
2800
ShowTables {
2801
+ terse : bool ,
2802
+ history : bool ,
2797
2803
extended : bool ,
2798
2804
full : bool ,
2799
- clause : Option < ShowClause > ,
2800
- db_name : Option < Ident > ,
2801
- filter : Option < ShowStatementFilter > ,
2805
+ external : bool ,
2806
+ show_options : ShowStatementOptions ,
2802
2807
} ,
2803
2808
/// ```sql
2804
2809
/// SHOW VIEWS
2805
2810
/// ```
2806
2811
ShowViews {
2812
+ terse : bool ,
2807
2813
materialized : bool ,
2808
- clause : Option < ShowClause > ,
2809
- db_name : Option < Ident > ,
2810
- filter : Option < ShowStatementFilter > ,
2814
+ show_options : ShowStatementOptions ,
2811
2815
} ,
2812
2816
/// ```sql
2813
2817
/// SHOW COLLATION
@@ -4387,79 +4391,72 @@ impl fmt::Display for Statement {
4387
4391
Statement :: ShowColumns {
4388
4392
extended,
4389
4393
full,
4390
- table_name,
4391
- filter,
4394
+ show_options,
4392
4395
} => {
4393
4396
write ! (
4394
4397
f,
4395
- "SHOW {extended}{full}COLUMNS FROM {table_name }" ,
4398
+ "SHOW {extended}{full}COLUMNS{show_options }" ,
4396
4399
extended = if * extended { "EXTENDED " } else { "" } ,
4397
4400
full = if * full { "FULL " } else { "" } ,
4398
- table_name = table_name,
4399
4401
) ?;
4400
- if let Some ( filter) = filter {
4401
- write ! ( f, " {filter}" ) ?;
4402
- }
4403
4402
Ok ( ( ) )
4404
4403
}
4405
- Statement :: ShowDatabases { filter } => {
4406
- write ! ( f, "SHOW DATABASES" ) ?;
4407
- if let Some ( filter) = filter {
4408
- write ! ( f, " {filter}" ) ?;
4409
- }
4404
+ Statement :: ShowDatabases {
4405
+ terse,
4406
+ history,
4407
+ show_options,
4408
+ } => {
4409
+ write ! (
4410
+ f,
4411
+ "SHOW {terse}DATABASES{history}{show_options}" ,
4412
+ terse = if * terse { "TERSE " } else { "" } ,
4413
+ history = if * history { " HISTORY" } else { "" } ,
4414
+ ) ?;
4410
4415
Ok ( ( ) )
4411
4416
}
4412
- Statement :: ShowSchemas { filter } => {
4413
- write ! ( f, "SHOW SCHEMAS" ) ?;
4414
- if let Some ( filter) = filter {
4415
- write ! ( f, " {filter}" ) ?;
4416
- }
4417
+ Statement :: ShowSchemas {
4418
+ terse,
4419
+ history,
4420
+ show_options,
4421
+ } => {
4422
+ write ! (
4423
+ f,
4424
+ "SHOW {terse}SCHEMAS{history}{show_options}" ,
4425
+ terse = if * terse { "TERSE " } else { "" } ,
4426
+ history = if * history { " HISTORY" } else { "" } ,
4427
+ ) ?;
4417
4428
Ok ( ( ) )
4418
4429
}
4419
4430
Statement :: ShowTables {
4431
+ terse,
4432
+ history,
4420
4433
extended,
4421
4434
full,
4422
- clause : show_clause,
4423
- db_name,
4424
- filter,
4435
+ external,
4436
+ show_options,
4425
4437
} => {
4426
4438
write ! (
4427
4439
f,
4428
- "SHOW {extended}{full}TABLES" ,
4440
+ "SHOW {terse}{extended}{full}{external}TABLES{history}{show_options}" ,
4441
+ terse = if * terse { "TERSE " } else { "" } ,
4429
4442
extended = if * extended { "EXTENDED " } else { "" } ,
4430
4443
full = if * full { "FULL " } else { "" } ,
4444
+ external = if * external { "EXTERNAL " } else { "" } ,
4445
+ history = if * history { " HISTORY" } else { "" } ,
4431
4446
) ?;
4432
- if let Some ( show_clause) = show_clause {
4433
- write ! ( f, " {show_clause}" ) ?;
4434
- }
4435
- if let Some ( db_name) = db_name {
4436
- write ! ( f, " {db_name}" ) ?;
4437
- }
4438
- if let Some ( filter) = filter {
4439
- write ! ( f, " {filter}" ) ?;
4440
- }
4441
4447
Ok ( ( ) )
4442
4448
}
4443
4449
Statement :: ShowViews {
4450
+ terse,
4444
4451
materialized,
4445
- clause : show_clause,
4446
- db_name,
4447
- filter,
4452
+ show_options,
4448
4453
} => {
4449
4454
write ! (
4450
4455
f,
4451
- "SHOW {}VIEWS" ,
4452
- if * materialized { "MATERIALIZED " } else { "" }
4456
+ "SHOW {terse}{materialized}VIEWS{show_options}" ,
4457
+ terse = if * terse { "TERSE " } else { "" } ,
4458
+ materialized = if * materialized { "MATERIALIZED " } else { "" }
4453
4459
) ?;
4454
- if let Some ( show_clause) = show_clause {
4455
- write ! ( f, " {show_clause}" ) ?;
4456
- }
4457
- if let Some ( db_name) = db_name {
4458
- write ! ( f, " {db_name}" ) ?;
4459
- }
4460
- if let Some ( filter) = filter {
4461
- write ! ( f, " {filter}" ) ?;
4462
- }
4463
4460
Ok ( ( ) )
4464
4461
}
4465
4462
Statement :: ShowFunctions { filter } => {
@@ -6172,14 +6169,14 @@ impl fmt::Display for ShowStatementFilter {
6172
6169
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6173
6170
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6174
6171
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6175
- pub enum ShowClause {
6172
+ pub enum ShowStatementInClause {
6176
6173
IN ,
6177
6174
FROM ,
6178
6175
}
6179
6176
6180
- impl fmt:: Display for ShowClause {
6177
+ impl fmt:: Display for ShowStatementInClause {
6181
6178
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6182
- use ShowClause :: * ;
6179
+ use ShowStatementInClause :: * ;
6183
6180
match self {
6184
6181
FROM => write ! ( f, "FROM" ) ,
6185
6182
IN => write ! ( f, "IN" ) ,
@@ -7357,6 +7354,108 @@ impl Display for UtilityOption {
7357
7354
}
7358
7355
}
7359
7356
7357
+ /// Represents the different options available for `SHOW`
7358
+ /// statements to filter the results. Example from Snowflake:
7359
+ /// <https://docs.snowflake.com/en/sql-reference/sql/show-tables>
7360
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7361
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7362
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7363
+ pub struct ShowStatementOptions {
7364
+ pub show_in : Option < ShowStatementIn > ,
7365
+ pub starts_with : Option < Value > ,
7366
+ pub limit : Option < Expr > ,
7367
+ pub limit_from : Option < Value > ,
7368
+ pub filter_position : Option < ShowStatementFilterPosition > ,
7369
+ }
7370
+
7371
+ impl Display for ShowStatementOptions {
7372
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
7373
+ let ( like_in_infix, like_in_suffix) = match & self . filter_position {
7374
+ Some ( ShowStatementFilterPosition :: Infix ( filter) ) => {
7375
+ ( format ! ( " {filter}" ) , "" . to_string ( ) )
7376
+ }
7377
+ Some ( ShowStatementFilterPosition :: Suffix ( filter) ) => {
7378
+ ( "" . to_string ( ) , format ! ( " {filter}" ) )
7379
+ }
7380
+ None => ( "" . to_string ( ) , "" . to_string ( ) ) ,
7381
+ } ;
7382
+ write ! (
7383
+ f,
7384
+ "{like_in_infix}{show_in}{starts_with}{limit}{from}{like_in_suffix}" ,
7385
+ show_in = match & self . show_in {
7386
+ Some ( i) => format!( " {i}" ) ,
7387
+ None => String :: new( ) ,
7388
+ } ,
7389
+ starts_with = match & self . starts_with {
7390
+ Some ( s) => format!( " STARTS WITH {s}" ) ,
7391
+ None => String :: new( ) ,
7392
+ } ,
7393
+ limit = match & self . limit {
7394
+ Some ( l) => format!( " LIMIT {l}" ) ,
7395
+ None => String :: new( ) ,
7396
+ } ,
7397
+ from = match & self . limit_from {
7398
+ Some ( f) => format!( " FROM {f}" ) ,
7399
+ None => String :: new( ) ,
7400
+ }
7401
+ ) ?;
7402
+ Ok ( ( ) )
7403
+ }
7404
+ }
7405
+
7406
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7407
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7408
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7409
+ pub enum ShowStatementFilterPosition {
7410
+ Infix ( ShowStatementFilter ) , // For example: SHOW COLUMNS LIKE '%name%' IN TABLE tbl
7411
+ Suffix ( ShowStatementFilter ) , // For example: SHOW COLUMNS IN tbl LIKE '%name%'
7412
+ }
7413
+
7414
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7415
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7416
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7417
+ pub enum ShowStatementInParentType {
7418
+ Account ,
7419
+ Database ,
7420
+ Schema ,
7421
+ Table ,
7422
+ View ,
7423
+ }
7424
+
7425
+ impl fmt:: Display for ShowStatementInParentType {
7426
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7427
+ match self {
7428
+ ShowStatementInParentType :: Account => write ! ( f, "ACCOUNT" ) ,
7429
+ ShowStatementInParentType :: Database => write ! ( f, "DATABASE" ) ,
7430
+ ShowStatementInParentType :: Schema => write ! ( f, "SCHEMA" ) ,
7431
+ ShowStatementInParentType :: Table => write ! ( f, "TABLE" ) ,
7432
+ ShowStatementInParentType :: View => write ! ( f, "VIEW" ) ,
7433
+ }
7434
+ }
7435
+ }
7436
+
7437
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7438
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7439
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7440
+ pub struct ShowStatementIn {
7441
+ pub clause : ShowStatementInClause ,
7442
+ pub parent_type : Option < ShowStatementInParentType > ,
7443
+ pub parent_name : Option < ObjectName > ,
7444
+ }
7445
+
7446
+ impl fmt:: Display for ShowStatementIn {
7447
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7448
+ write ! ( f, "{}" , self . clause) ?;
7449
+ if let Some ( parent_type) = & self . parent_type {
7450
+ write ! ( f, " {}" , parent_type) ?;
7451
+ }
7452
+ if let Some ( parent_name) = & self . parent_name {
7453
+ write ! ( f, " {}" , parent_name) ?;
7454
+ }
7455
+ Ok ( ( ) )
7456
+ }
7457
+ }
7458
+
7360
7459
#[ cfg( test) ]
7361
7460
mod tests {
7362
7461
use super :: * ;
0 commit comments