File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -383,6 +383,16 @@ impl CreateTableBuilder {
383
383
self
384
384
}
385
385
386
+ /// Returns true if information on the structure of the table
387
+ /// to be created was provided to the builder. If not, the
388
+ /// statement is invalid.
389
+ pub fn has_schema_info ( & self ) -> bool {
390
+ !self . columns . is_empty ( )
391
+ || self . query . is_some ( )
392
+ || self . like . is_some ( )
393
+ || self . clone . is_some ( )
394
+ }
395
+
386
396
pub fn build ( self ) -> Statement {
387
397
Statement :: CreateTable ( CreateTable {
388
398
or_replace : self . or_replace ,
Original file line number Diff line number Diff line change @@ -473,12 +473,10 @@ pub fn parse_create_table(
473
473
Keyword :: CLONE => {
474
474
let clone = parser. parse_object_name ( false ) . ok ( ) ;
475
475
builder = builder. clone_clause ( clone) ;
476
- break ;
477
476
}
478
477
Keyword :: LIKE => {
479
478
let like = parser. parse_object_name ( false ) . ok ( ) ;
480
479
builder = builder. like ( like) ;
481
- break ;
482
480
}
483
481
Keyword :: CLUSTER => {
484
482
parser. expect_keyword_is ( Keyword :: BY ) ?;
@@ -604,7 +602,7 @@ pub fn parse_create_table(
604
602
builder = builder. columns ( columns) . constraints ( constraints) ;
605
603
}
606
604
Token :: EOF => {
607
- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
605
+ if ! builder. has_schema_info ( ) {
608
606
return Err ( ParserError :: ParserError (
609
607
"unexpected end of input" . to_string ( ) ,
610
608
) ) ;
@@ -613,7 +611,7 @@ pub fn parse_create_table(
613
611
break ;
614
612
}
615
613
Token :: SemiColon => {
616
- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
614
+ if ! builder. has_schema_info ( ) {
617
615
return Err ( ParserError :: ParserError (
618
616
"unexpected end of input" . to_string ( ) ,
619
617
) ) ;
Original file line number Diff line number Diff line change @@ -996,13 +996,18 @@ fn test_snowflake_create_iceberg_table_without_location() {
996
996
}
997
997
998
998
#[ test]
999
- fn test_snowflake_create_table_as ( ) {
1000
- // Test additional options after AS (query)
999
+ fn test_snowflake_create_table_trailing_options ( ) {
1001
1000
snowflake ( )
1002
1001
. parse_sql_statements (
1003
1002
"CREATE TEMP TABLE dst AS (SELECT * FROM src) ON COMMIT PRESERVE ROWS" ,
1004
1003
)
1005
1004
. unwrap ( ) ;
1005
+ snowflake ( )
1006
+ . parse_sql_statements ( "CREATE TEMP TABLE tbl LIKE customers ON COMMIT PRESERVE ROWS;" )
1007
+ . unwrap ( ) ;
1008
+ snowflake ( )
1009
+ . parse_sql_statements ( "CREATE TEMP TABLE tbl CLONE customers ON COMMIT PRESERVE ROWS;" )
1010
+ . unwrap ( ) ;
1006
1011
}
1007
1012
1008
1013
#[ test]
You can’t perform that action at this time.
0 commit comments