@@ -34,7 +34,7 @@ pub use self::ddl::{
34
34
AlterColumnOperation , AlterIndexOperation , AlterTableOperation , ColumnDef , ColumnOption ,
35
35
ColumnOptionDef , GeneratedAs , GeneratedExpressionMode , IndexType , KeyOrIndexDisplay , Partition ,
36
36
ProcedureParam , ReferentialAction , TableConstraint , UserDefinedTypeCompositeAttributeDef ,
37
- UserDefinedTypeRepresentation ,
37
+ UserDefinedTypeRepresentation , ViewColumnDef ,
38
38
} ;
39
39
pub use self :: operator:: { BinaryOperator , UnaryOperator } ;
40
40
pub use self :: query:: {
@@ -1367,6 +1367,38 @@ pub enum Password {
1367
1367
NullPassword ,
1368
1368
}
1369
1369
1370
+ /// Sql options of a `CREATE TABLE` statement.
1371
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1372
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1373
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1374
+ pub enum CreateTableOptions {
1375
+ None ,
1376
+ /// Options specified using the `WITH` keyword.
1377
+ /// e.g. `WITH (description = "123")`
1378
+ ///
1379
+ /// <https://www.postgresql.org/docs/current/sql-createtable.html>
1380
+ With ( Vec < SqlOption > ) ,
1381
+ /// Options specified using the `OPTIONS` keyword.
1382
+ /// e.g. `OPTIONS(description = "123")`
1383
+ ///
1384
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
1385
+ Options ( Vec < SqlOption > ) ,
1386
+ }
1387
+
1388
+ impl fmt:: Display for CreateTableOptions {
1389
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1390
+ match self {
1391
+ CreateTableOptions :: With ( with_options) => {
1392
+ write ! ( f, "WITH ({})" , display_comma_separated( with_options) )
1393
+ }
1394
+ CreateTableOptions :: Options ( options) => {
1395
+ write ! ( f, "OPTIONS({})" , display_comma_separated( options) )
1396
+ }
1397
+ CreateTableOptions :: None => Ok ( ( ) ) ,
1398
+ }
1399
+ }
1400
+ }
1401
+
1370
1402
/// A top-level statement (SELECT, INSERT, CREATE, etc.)
1371
1403
#[ allow( clippy:: large_enum_variant) ]
1372
1404
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -1550,9 +1582,9 @@ pub enum Statement {
1550
1582
materialized : bool ,
1551
1583
/// View name
1552
1584
name : ObjectName ,
1553
- columns : Vec < Ident > ,
1585
+ columns : Vec < ViewColumnDef > ,
1554
1586
query : Box < Query > ,
1555
- with_options : Vec < SqlOption > ,
1587
+ options : CreateTableOptions ,
1556
1588
cluster_by : Vec < Ident > ,
1557
1589
/// if true, has RedShift [`WITH NO SCHEMA BINDING`] clause <https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_VIEW.html>
1558
1590
with_no_schema_binding : bool ,
@@ -1600,6 +1632,15 @@ pub enum Statement {
1600
1632
/// than empty (represented as ()), the latter meaning "no sorting".
1601
1633
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/table/>
1602
1634
order_by : Option < Vec < Ident > > ,
1635
+ /// BigQuery: A partition expression for the table.
1636
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#partition_expression>
1637
+ partition_by : Option < Box < Expr > > ,
1638
+ /// BigQuery: Table clustering column list.
1639
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
1640
+ cluster_by : Option < Vec < Ident > > ,
1641
+ /// BigQuery: Table options list.
1642
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
1643
+ options : Option < Vec < SqlOption > > ,
1603
1644
/// SQLite "STRICT" clause.
1604
1645
/// if the "STRICT" table-option keyword is added to the end, after the closing ")",
1605
1646
/// then strict typing rules apply to that table.
@@ -2731,7 +2772,7 @@ impl fmt::Display for Statement {
2731
2772
columns,
2732
2773
query,
2733
2774
materialized,
2734
- with_options ,
2775
+ options ,
2735
2776
cluster_by,
2736
2777
with_no_schema_binding,
2737
2778
if_not_exists,
@@ -2746,15 +2787,18 @@ impl fmt::Display for Statement {
2746
2787
temporary = if * temporary { "TEMPORARY " } else { "" } ,
2747
2788
if_not_exists = if * if_not_exists { "IF NOT EXISTS " } else { "" }
2748
2789
) ?;
2749
- if !with_options . is_empty ( ) {
2750
- write ! ( f, " WITH ({})" , display_comma_separated ( with_options ) ) ?;
2790
+ if matches ! ( options , CreateTableOptions :: With ( _ ) ) {
2791
+ write ! ( f, " {options}" ) ?;
2751
2792
}
2752
2793
if !columns. is_empty ( ) {
2753
2794
write ! ( f, " ({})" , display_comma_separated( columns) ) ?;
2754
2795
}
2755
2796
if !cluster_by. is_empty ( ) {
2756
2797
write ! ( f, " CLUSTER BY ({})" , display_comma_separated( cluster_by) ) ?;
2757
2798
}
2799
+ if matches ! ( options, CreateTableOptions :: Options ( _) ) {
2800
+ write ! ( f, " {options}" ) ?;
2801
+ }
2758
2802
write ! ( f, " AS {query}" ) ?;
2759
2803
if * with_no_schema_binding {
2760
2804
write ! ( f, " WITH NO SCHEMA BINDING" ) ?;
@@ -2789,6 +2833,9 @@ impl fmt::Display for Statement {
2789
2833
on_commit,
2790
2834
on_cluster,
2791
2835
order_by,
2836
+ partition_by,
2837
+ cluster_by,
2838
+ options,
2792
2839
strict,
2793
2840
} => {
2794
2841
// We want to allow the following options
@@ -2945,6 +2992,23 @@ impl fmt::Display for Statement {
2945
2992
if let Some ( order_by) = order_by {
2946
2993
write ! ( f, " ORDER BY ({})" , display_comma_separated( order_by) ) ?;
2947
2994
}
2995
+ if let Some ( partition_by) = partition_by. as_ref ( ) {
2996
+ write ! ( f, " PARTITION BY {partition_by}" ) ?;
2997
+ }
2998
+ if let Some ( cluster_by) = cluster_by. as_ref ( ) {
2999
+ write ! (
3000
+ f,
3001
+ " CLUSTER BY {}" ,
3002
+ display_comma_separated( cluster_by. as_slice( ) )
3003
+ ) ?;
3004
+ }
3005
+ if let Some ( options) = options. as_ref ( ) {
3006
+ write ! (
3007
+ f,
3008
+ " OPTIONS({})" ,
3009
+ display_comma_separated( options. as_slice( ) )
3010
+ ) ?;
3011
+ }
2948
3012
if let Some ( query) = query {
2949
3013
write ! ( f, " AS {query}" ) ?;
2950
3014
}
@@ -4496,7 +4560,7 @@ pub struct HiveFormat {
4496
4560
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
4497
4561
pub struct SqlOption {
4498
4562
pub name : Ident ,
4499
- pub value : Value ,
4563
+ pub value : Expr ,
4500
4564
}
4501
4565
4502
4566
impl fmt:: Display for SqlOption {
0 commit comments