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 @@ -456,12 +456,10 @@ pub fn parse_create_table(
456
456
Keyword :: CLONE => {
457
457
let clone = parser. parse_object_name ( false ) . ok ( ) ;
458
458
builder = builder. clone_clause ( clone) ;
459
- break ;
460
459
}
461
460
Keyword :: LIKE => {
462
461
let like = parser. parse_object_name ( false ) . ok ( ) ;
463
462
builder = builder. like ( like) ;
464
- break ;
465
463
}
466
464
Keyword :: CLUSTER => {
467
465
parser. expect_keyword_is ( Keyword :: BY ) ?;
@@ -587,7 +585,7 @@ pub fn parse_create_table(
587
585
builder = builder. columns ( columns) . constraints ( constraints) ;
588
586
}
589
587
Token :: EOF => {
590
- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
588
+ if ! builder. has_schema_info ( ) {
591
589
return Err ( ParserError :: ParserError (
592
590
"unexpected end of input" . to_string ( ) ,
593
591
) ) ;
@@ -596,7 +594,7 @@ pub fn parse_create_table(
596
594
break ;
597
595
}
598
596
Token :: SemiColon => {
599
- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
597
+ if ! builder. has_schema_info ( ) {
600
598
return Err ( ParserError :: ParserError (
601
599
"unexpected end of input" . to_string ( ) ,
602
600
) ) ;
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