@@ -34,7 +34,7 @@ pub use self::ddl::{
3434 AlterColumnOperation , AlterIndexOperation , AlterTableOperation , ColumnDef , ColumnOption ,
3535 ColumnOptionDef , GeneratedAs , GeneratedExpressionMode , IndexType , KeyOrIndexDisplay , Partition ,
3636 ProcedureParam , ReferentialAction , TableConstraint , UserDefinedTypeCompositeAttributeDef ,
37- UserDefinedTypeRepresentation ,
37+ UserDefinedTypeRepresentation , ViewColumnDef ,
3838} ;
3939pub use self :: operator:: { BinaryOperator , UnaryOperator } ;
4040pub use self :: query:: {
@@ -1367,6 +1367,38 @@ pub enum Password {
13671367 NullPassword ,
13681368}
13691369
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+
13701402/// A top-level statement (SELECT, INSERT, CREATE, etc.)
13711403#[ allow( clippy:: large_enum_variant) ]
13721404#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -1550,9 +1582,9 @@ pub enum Statement {
15501582 materialized : bool ,
15511583 /// View name
15521584 name : ObjectName ,
1553- columns : Vec < Ident > ,
1585+ columns : Vec < ViewColumnDef > ,
15541586 query : Box < Query > ,
1555- with_options : Vec < SqlOption > ,
1587+ options : CreateTableOptions ,
15561588 cluster_by : Vec < Ident > ,
15571589 /// if true, has RedShift [`WITH NO SCHEMA BINDING`] clause <https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_VIEW.html>
15581590 with_no_schema_binding : bool ,
@@ -1600,6 +1632,15 @@ pub enum Statement {
16001632 /// than empty (represented as ()), the latter meaning "no sorting".
16011633 /// <https://clickhouse.com/docs/en/sql-reference/statements/create/table/>
16021634 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 > > ,
16031644 /// SQLite "STRICT" clause.
16041645 /// if the "STRICT" table-option keyword is added to the end, after the closing ")",
16051646 /// then strict typing rules apply to that table.
@@ -2731,7 +2772,7 @@ impl fmt::Display for Statement {
27312772 columns,
27322773 query,
27332774 materialized,
2734- with_options ,
2775+ options ,
27352776 cluster_by,
27362777 with_no_schema_binding,
27372778 if_not_exists,
@@ -2746,15 +2787,18 @@ impl fmt::Display for Statement {
27462787 temporary = if * temporary { "TEMPORARY " } else { "" } ,
27472788 if_not_exists = if * if_not_exists { "IF NOT EXISTS " } else { "" }
27482789 ) ?;
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}" ) ?;
27512792 }
27522793 if !columns. is_empty ( ) {
27532794 write ! ( f, " ({})" , display_comma_separated( columns) ) ?;
27542795 }
27552796 if !cluster_by. is_empty ( ) {
27562797 write ! ( f, " CLUSTER BY ({})" , display_comma_separated( cluster_by) ) ?;
27572798 }
2799+ if matches ! ( options, CreateTableOptions :: Options ( _) ) {
2800+ write ! ( f, " {options}" ) ?;
2801+ }
27582802 write ! ( f, " AS {query}" ) ?;
27592803 if * with_no_schema_binding {
27602804 write ! ( f, " WITH NO SCHEMA BINDING" ) ?;
@@ -2789,6 +2833,9 @@ impl fmt::Display for Statement {
27892833 on_commit,
27902834 on_cluster,
27912835 order_by,
2836+ partition_by,
2837+ cluster_by,
2838+ options,
27922839 strict,
27932840 } => {
27942841 // We want to allow the following options
@@ -2945,6 +2992,23 @@ impl fmt::Display for Statement {
29452992 if let Some ( order_by) = order_by {
29462993 write ! ( f, " ORDER BY ({})" , display_comma_separated( order_by) ) ?;
29472994 }
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+ }
29483012 if let Some ( query) = query {
29493013 write ! ( f, " AS {query}" ) ?;
29503014 }
@@ -4496,7 +4560,7 @@ pub struct HiveFormat {
44964560#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
44974561pub struct SqlOption {
44984562 pub name : Ident ,
4499- pub value : Value ,
4563+ pub value : Expr ,
45004564}
45014565
45024566impl fmt:: Display for SqlOption {
0 commit comments