@@ -29,20 +29,15 @@ use serde::{Deserialize, Serialize};
2929#[ cfg( feature = "visitor" ) ]
3030use sqlparser_derive:: { Visit , VisitMut } ;
3131
32- use crate :: parser:: {
33- Compression , DelayKeyWrite , DirectoryOption , Encryption , InsertMethod , OptionState , RowFormat ,
34- StorageType , TablespaceOption ,
35- } ;
36-
3732pub use super :: ddl:: { ColumnDef , TableConstraint } ;
3833
3934use super :: {
4035 display_comma_separated, display_separated, query:: InputFormatClause , Assignment , ClusteredBy ,
4136 CommentDef , Expr , FileFormat , FromTable , HiveDistributionStyle , HiveFormat , HiveIOFormat ,
4237 HiveRowFormat , Ident , IndexType , InsertAliases , MysqlInsertPriority , ObjectName , OnCommit ,
4338 OnInsert , OneOrManyWithParens , OrderByExpr , Query , RowAccessPolicy , SelectItem , Setting ,
44- SqlOption , SqliteOnConflict , StorageSerializationPolicy , TableEngine , TableObject ,
45- TableWithJoins , Tag , WrappedCollection ,
39+ SqlOption , SqliteOnConflict , StorageSerializationPolicy , TableObject , TableWithJoins , Tag ,
40+ WrappedCollection ,
4641} ;
4742
4843/// Index column type.
@@ -153,41 +148,19 @@ pub struct CreateTable {
153148 pub hive_formats : Option < HiveFormat > ,
154149 pub table_properties : Vec < SqlOption > ,
155150 pub with_options : Vec < SqlOption > ,
151+ /// BigQuery: Table options list.
152+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
153+ pub options : Option < Vec < SqlOption > > ,
154+ /// Plain options, options which are not part on any declerative statement e.g. WITH/OPTIONS/...
155+ /// <https://dev.mysql.com/doc/refman/8.4/en/create-table.html>
156+ pub plain_options : Vec < SqlOption > ,
156157 pub file_format : Option < FileFormat > ,
157158 pub location : Option < String > ,
158159 pub query : Option < Box < Query > > ,
159160 pub without_rowid : bool ,
160161 pub like : Option < ObjectName > ,
161162 pub clone : Option < ObjectName > ,
162- pub engine : Option < TableEngine > ,
163163 pub comment : Option < CommentDef > ,
164- pub auto_increment_offset : Option < u32 > ,
165- pub key_block_size : Option < u32 > ,
166- pub max_rows : Option < u32 > ,
167- pub min_rows : Option < u32 > ,
168- pub autoextend_size : Option < u32 > ,
169- pub avg_row_length : Option < u32 > ,
170- pub checksum : Option < bool > ,
171- pub connection : Option < String > ,
172- pub engine_attribute : Option < String > ,
173- pub password : Option < String > ,
174- pub secondary_engine_attribute : Option < String > ,
175- pub tablespace_option : Option < TablespaceOption > ,
176- pub row_format : Option < RowFormat > ,
177- pub insert_method : Option < InsertMethod > ,
178- pub compression : Option < Compression > ,
179- pub delay_key_write : Option < DelayKeyWrite > ,
180- pub encryption : Option < Encryption > ,
181- pub pack_keys : Option < OptionState > ,
182- pub stats_auto_recalc : Option < OptionState > ,
183- pub stats_persistent : Option < OptionState > ,
184- pub stats_sample_pages : Option < u32 > ,
185- pub start_transaction : Option < bool > ,
186- pub union_tables : Option < Vec < String > > ,
187- pub data_directory : Option < DirectoryOption > ,
188- pub index_directory : Option < DirectoryOption > ,
189- pub default_charset : Option < String > ,
190- pub collation : Option < String > ,
191164 pub on_commit : Option < OnCommit > ,
192165 /// ClickHouse "ON CLUSTER" clause:
193166 /// <https://clickhouse.com/docs/en/sql-reference/distributed-ddl/>
@@ -208,9 +181,6 @@ pub struct CreateTable {
208181 /// Hive: Table clustering column list.
209182 /// <https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable>
210183 pub clustered_by : Option < ClusteredBy > ,
211- /// BigQuery: Table options list.
212- /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
213- pub options : Option < Vec < SqlOption > > ,
214184 /// SQLite "STRICT" clause.
215185 /// if the "STRICT" table-option keyword is added to the end, after the closing ")",
216186 /// then strict typing rules apply to that table.
@@ -409,9 +379,11 @@ impl Display for CreateTable {
409379 if !self . with_options . is_empty ( ) {
410380 write ! ( f, " WITH ({})" , display_comma_separated( & self . with_options) ) ?;
411381 }
412- if let Some ( engine) = & self . engine {
413- write ! ( f, " ENGINE={engine}" ) ?;
382+
383+ if !self . plain_options . is_empty ( ) {
384+ write ! ( f, " {}" , display_separated( & self . plain_options, " " ) ) ?;
414385 }
386+
415387 if let Some ( comment_def) = & self . comment {
416388 match comment_def {
417389 CommentDef :: WithEq ( comment) => {
@@ -425,9 +397,6 @@ impl Display for CreateTable {
425397 }
426398 }
427399
428- if let Some ( auto_increment_offset) = self . auto_increment_offset {
429- write ! ( f, " AUTO_INCREMENT={auto_increment_offset}" ) ?;
430- }
431400 if let Some ( primary_key) = & self . primary_key {
432401 write ! ( f, " PRIMARY KEY {}" , primary_key) ?;
433402 }
@@ -524,165 +493,6 @@ impl Display for CreateTable {
524493 write ! ( f, " WITH TAG ({})" , display_comma_separated( tag. as_slice( ) ) ) ?;
525494 }
526495
527- if let Some ( default_charset) = & self . default_charset {
528- write ! ( f, " DEFAULT CHARSET={default_charset}" ) ?;
529- }
530- if let Some ( collation) = & self . collation {
531- write ! ( f, " COLLATE={collation}" ) ?;
532- }
533-
534- if let Some ( insert_method) = & self . insert_method {
535- match insert_method {
536- InsertMethod :: No => write ! ( f, " INSERT_METHOD=NO" ) ?,
537- InsertMethod :: First => write ! ( f, " INSERT_METHOD=FIRST" ) ?,
538- InsertMethod :: Last => write ! ( f, " INSERT_METHOD=LAST" ) ?,
539- }
540- }
541-
542- if let Some ( key_block_size) = self . key_block_size {
543- write ! ( f, " KEY_BLOCK_SIZE={key_block_size}" ) ?;
544- }
545-
546- if let Some ( row_format) = & self . row_format {
547- match row_format {
548- RowFormat :: Default => write ! ( f, " ROW_FORMAT=DEFAULT" ) ?,
549- RowFormat :: Dynamic => write ! ( f, " ROW_FORMAT=DYNAMIC" ) ?,
550- RowFormat :: Fixed => write ! ( f, " ROW_FORMAT=FIXED" ) ?,
551- RowFormat :: Compressed => write ! ( f, " ROW_FORMAT=COMPRESSED" ) ?,
552- RowFormat :: Redundant => write ! ( f, " ROW_FORMAT=REDUNDANT" ) ?,
553- RowFormat :: Compact => write ! ( f, " ROW_FORMAT=COMPACT" ) ?,
554- }
555- }
556-
557- if let Some ( data_dir) = & self . data_directory {
558- write ! ( f, " DATA DIRECTORY='{}'" , data_dir. path) ?;
559- }
560-
561- if let Some ( index_dir) = & self . index_directory {
562- write ! ( f, " INDEX DIRECTORY='{}'" , index_dir. path) ?;
563- }
564-
565- if let Some ( pack_keys) = & self . pack_keys {
566- match pack_keys {
567- OptionState :: Default => write ! ( f, " PACK_KEYS=DEFAULT" ) ?,
568- OptionState :: One => write ! ( f, " PACK_KEYS=1" ) ?,
569- OptionState :: Zero => write ! ( f, " PACK_KEYS=0" ) ?,
570- }
571- }
572-
573- if let Some ( stats_auto_recalc) = & self . stats_auto_recalc {
574- match stats_auto_recalc {
575- OptionState :: Default => write ! ( f, " STATS_AUTO_RECALC=DEFAULT" ) ?,
576- OptionState :: One => write ! ( f, " STATS_AUTO_RECALC=1" ) ?,
577- OptionState :: Zero => write ! ( f, " STATS_AUTO_RECALC=0" ) ?,
578- }
579- }
580-
581- if let Some ( stats_persistent) = & self . stats_persistent {
582- match stats_persistent {
583- OptionState :: Default => write ! ( f, " STATS_PERSISTENT=DEFAULT" ) ?,
584- OptionState :: One => write ! ( f, " STATS_PERSISTENT=1" ) ?,
585- OptionState :: Zero => write ! ( f, " STATS_PERSISTENT=0" ) ?,
586- }
587- }
588-
589- if let Some ( stats_sample_pages) = self . stats_sample_pages {
590- write ! ( f, " STATS_SAMPLE_PAGES={stats_sample_pages}" ) ?;
591- }
592-
593- if let Some ( delay_key_write) = & self . delay_key_write {
594- match delay_key_write {
595- DelayKeyWrite :: Enabled => write ! ( f, " DELAY_KEY_WRITE=1" ) ?,
596- DelayKeyWrite :: Disabled => write ! ( f, " DELAY_KEY_WRITE=0" ) ?,
597- }
598- }
599-
600- if let Some ( compression) = & self . compression {
601- match compression {
602- Compression :: Lz4 => write ! ( f, " COMPRESSION=LZ4" ) ?,
603- Compression :: Zlib => write ! ( f, " COMPRESSION=ZLIB" ) ?,
604- Compression :: None => write ! ( f, " COMPRESSION=NONE" ) ?,
605- }
606- }
607-
608- if let Some ( encryption) = & self . encryption {
609- match encryption {
610- Encryption :: Yes => write ! ( f, " ENCRYPTION='Y'" ) ?,
611- Encryption :: No => write ! ( f, " ENCRYPTION='N'" ) ?,
612- }
613- }
614-
615- if let Some ( max_rows) = & self . max_rows {
616- write ! ( f, " MAX_ROWS={}" , max_rows) ?;
617- }
618-
619- if let Some ( min_rows) = & self . min_rows {
620- write ! ( f, " MIN_ROWS={}" , min_rows) ?;
621- }
622-
623- if let Some ( autoextend_size) = & self . autoextend_size {
624- write ! ( f, " AUTOEXTEND_SIZE={}" , autoextend_size) ?;
625- }
626-
627- if let Some ( avg_row_length) = & self . avg_row_length {
628- write ! ( f, " AVG_ROW_LENGTH={}" , avg_row_length) ?;
629- }
630-
631- if let Some ( checksum) = & self . checksum {
632- match checksum {
633- true => write ! ( f, " CHECKSUM=1" ) ?,
634- false => write ! ( f, " CHECKSUM=0" ) ?,
635- }
636- }
637-
638- if let Some ( connection) = & self . connection {
639- write ! ( f, " CONNECTION='{}'" , connection) ?;
640- }
641-
642- if let Some ( engine_attribute) = & self . engine_attribute {
643- write ! ( f, " ENGINE_ATTRIBUTE='{}'" , engine_attribute) ?;
644- }
645-
646- if let Some ( password) = & self . password {
647- write ! ( f, " PASSWORD='{}'" , password) ?;
648- }
649-
650- if let Some ( secondary_engine_attribute) = & self . secondary_engine_attribute {
651- write ! (
652- f,
653- " SECONDARY_ENGINE_ATTRIBUTE='{}'" ,
654- secondary_engine_attribute
655- ) ?;
656- }
657-
658- if self . start_transaction . unwrap_or ( false ) {
659- write ! ( f, " START TRANSACTION" ) ?;
660- }
661-
662- if let Some ( tablespace_option) = & self . tablespace_option {
663- write ! ( f, " TABLESPACE {}" , tablespace_option. name) ?;
664- if let Some ( storage) = & tablespace_option. storage {
665- match storage {
666- StorageType :: Disk => write ! ( f, " STORAGE DISK" ) ?,
667- StorageType :: Memory => write ! ( f, " STORAGE MEMORY" ) ?,
668- }
669- }
670- }
671-
672- if let Some ( union_tables) = & self . union_tables {
673- if !union_tables. is_empty ( ) {
674- write ! (
675- f,
676- " UNION=({})" ,
677- union_tables
678- . iter( )
679- . map( |table| table. to_string( ) )
680- . collect:: <Vec <String >>( )
681- . join( ", " )
682- ) ?;
683- }
684- }
685-
686496 if self . on_commit . is_some ( ) {
687497 let on_commit = match self . on_commit {
688498 Some ( OnCommit :: DeleteRows ) => "ON COMMIT DELETE ROWS" ,
0 commit comments