@@ -1511,6 +1511,20 @@ pub enum Statement {
1511
1511
/// RETURNING
1512
1512
returning : Option < Vec < WithSpan < SelectItem > > > ,
1513
1513
} ,
1514
+ /// ```sql
1515
+ /// INSTALL
1516
+ /// ```
1517
+ Install {
1518
+ /// Only for DuckDB
1519
+ extension_name : WithSpan < Ident > ,
1520
+ } ,
1521
+ /// ```sql
1522
+ /// LOAD
1523
+ /// ```
1524
+ Load {
1525
+ /// Only for DuckDB
1526
+ extension_name : WithSpan < Ident > ,
1527
+ } ,
1514
1528
// TODO: Support ROW FORMAT
1515
1529
Directory {
1516
1530
overwrite : bool ,
@@ -2231,6 +2245,46 @@ pub enum Statement {
2231
2245
name : ObjectName ,
2232
2246
representation : UserDefinedTypeRepresentation ,
2233
2247
} ,
2248
+ /// ```sql
2249
+ /// PRAGMA <schema-name>.<pragma-name> = <pragma-value>
2250
+ /// ```
2251
+ Pragma {
2252
+ name : ObjectName ,
2253
+ value : Option < Value > ,
2254
+ is_eq : bool ,
2255
+ } ,
2256
+ /// ```sql
2257
+ /// LOCK TABLES <table_name> [READ [LOCAL] | [LOW_PRIORITY] WRITE]
2258
+ /// ```
2259
+ /// Note: this is a MySQL-specific statement. See <https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html>
2260
+ LockTables { tables : Vec < LockTable > } ,
2261
+ /// ```sql
2262
+ /// UNLOCK TABLES
2263
+ /// ```
2264
+ /// Note: this is a MySQL-specific statement. See <https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html>
2265
+ UnlockTables ,
2266
+ /// ```sql
2267
+ /// UNLOAD(statement) TO <destination> [ WITH options ]
2268
+ /// ```
2269
+ /// See Redshift <https://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD.html> and
2270
+ // Athena <https://docs.aws.amazon.com/athena/latest/ug/unload.html>
2271
+ Unload {
2272
+ query : Box < Query > ,
2273
+ to : WithSpan < Ident > ,
2274
+ with : Vec < SqlOption > ,
2275
+ } ,
2276
+ /// ```sql
2277
+ /// OPTIMIZE TABLE [db.]name [ON CLUSTER cluster] [PARTITION partition | PARTITION ID 'partition_id'] [FINAL] [DEDUPLICATE [BY expression]]
2278
+ /// ```
2279
+ ///
2280
+ /// See ClickHouse <https://clickhouse.com/docs/en/sql-reference/statements/optimize>
2281
+ OptimizeTable {
2282
+ name : ObjectName ,
2283
+ on_cluster : Option < WithSpan < Ident > > ,
2284
+ partition : Option < Partition > ,
2285
+ include_final : bool ,
2286
+ deduplicate : Option < Deduplicate > ,
2287
+ } ,
2234
2288
}
2235
2289
2236
2290
impl fmt:: Display for Statement {
@@ -2476,6 +2530,14 @@ impl fmt::Display for Statement {
2476
2530
Ok ( ( ) )
2477
2531
}
2478
2532
2533
+ Statement :: Install {
2534
+ extension_name : name,
2535
+ } => write ! ( f, "INSTALL {name}" ) ,
2536
+
2537
+ Statement :: Load {
2538
+ extension_name : name,
2539
+ } => write ! ( f, "LOAD {name}" ) ,
2540
+
2479
2541
Statement :: Call ( function) => write ! ( f, "CALL {function}" ) ,
2480
2542
2481
2543
Statement :: Copy {
@@ -3710,6 +3772,55 @@ impl fmt::Display for Statement {
3710
3772
} => {
3711
3773
write ! ( f, "CREATE TYPE {name} AS {representation}" )
3712
3774
}
3775
+ Statement :: Pragma { name, value, is_eq } => {
3776
+ write ! ( f, "PRAGMA {name}" ) ?;
3777
+ if value. is_some ( ) {
3778
+ let val = value. as_ref ( ) . unwrap ( ) ;
3779
+ if * is_eq {
3780
+ write ! ( f, " = {val}" ) ?;
3781
+ } else {
3782
+ write ! ( f, "({val})" ) ?;
3783
+ }
3784
+ }
3785
+ Ok ( ( ) )
3786
+ }
3787
+ Statement :: LockTables { tables } => {
3788
+ write ! ( f, "LOCK TABLES {}" , display_comma_separated( tables) )
3789
+ }
3790
+ Statement :: UnlockTables => {
3791
+ write ! ( f, "UNLOCK TABLES" )
3792
+ }
3793
+ Statement :: Unload { query, to, with } => {
3794
+ write ! ( f, "UNLOAD({query}) TO {to}" ) ?;
3795
+
3796
+ if !with. is_empty ( ) {
3797
+ write ! ( f, " WITH ({})" , display_comma_separated( with) ) ?;
3798
+ }
3799
+
3800
+ Ok ( ( ) )
3801
+ }
3802
+ Statement :: OptimizeTable {
3803
+ name,
3804
+ on_cluster,
3805
+ partition,
3806
+ include_final,
3807
+ deduplicate,
3808
+ } => {
3809
+ write ! ( f, "OPTIMIZE TABLE {name}" ) ?;
3810
+ if let Some ( on_cluster) = on_cluster {
3811
+ write ! ( f, " ON CLUSTER {on_cluster}" , on_cluster = on_cluster) ?;
3812
+ }
3813
+ if let Some ( partition) = partition {
3814
+ write ! ( f, " {partition}" , partition = partition) ?;
3815
+ }
3816
+ if * include_final {
3817
+ write ! ( f, " FINAL" ) ?;
3818
+ }
3819
+ if let Some ( deduplicate) = deduplicate {
3820
+ write ! ( f, " {deduplicate}" ) ?;
3821
+ }
3822
+ Ok ( ( ) )
3823
+ }
3713
3824
}
3714
3825
}
3715
3826
}
@@ -5210,6 +5321,61 @@ impl fmt::Display for SearchModifier {
5210
5321
}
5211
5322
}
5212
5323
5324
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5325
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5326
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5327
+ pub struct LockTable {
5328
+ pub table : Ident ,
5329
+ pub alias : Option < Ident > ,
5330
+ pub lock_type : LockTableType ,
5331
+ }
5332
+
5333
+ impl fmt:: Display for LockTable {
5334
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5335
+ let Self {
5336
+ table : tbl_name,
5337
+ alias,
5338
+ lock_type,
5339
+ } = self ;
5340
+
5341
+ write ! ( f, "{tbl_name} " ) ?;
5342
+ if let Some ( alias) = alias {
5343
+ write ! ( f, "AS {alias} " ) ?;
5344
+ }
5345
+ write ! ( f, "{lock_type}" ) ?;
5346
+ Ok ( ( ) )
5347
+ }
5348
+ }
5349
+
5350
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5351
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5352
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5353
+ pub enum LockTableType {
5354
+ Read { local : bool } ,
5355
+ Write { low_priority : bool } ,
5356
+ }
5357
+
5358
+ impl fmt:: Display for LockTableType {
5359
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5360
+ match self {
5361
+ Self :: Read { local } => {
5362
+ write ! ( f, "READ" ) ?;
5363
+ if * local {
5364
+ write ! ( f, " LOCAL" ) ?;
5365
+ }
5366
+ }
5367
+ Self :: Write { low_priority } => {
5368
+ if * low_priority {
5369
+ write ! ( f, "LOW_PRIORITY " ) ?;
5370
+ }
5371
+ write ! ( f, "WRITE" ) ?;
5372
+ }
5373
+ }
5374
+
5375
+ Ok ( ( ) )
5376
+ }
5377
+ }
5378
+
5213
5379
#[ cfg( test) ]
5214
5380
mod tests {
5215
5381
use super :: * ;
0 commit comments