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 {
383383 self
384384 }
385385
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+
386396 pub fn build ( self ) -> Statement {
387397 Statement :: CreateTable ( CreateTable {
388398 or_replace : self . or_replace ,
Original file line number Diff line number Diff line change @@ -456,12 +456,10 @@ pub fn parse_create_table(
456456 Keyword :: CLONE => {
457457 let clone = parser. parse_object_name ( false ) . ok ( ) ;
458458 builder = builder. clone_clause ( clone) ;
459- break ;
460459 }
461460 Keyword :: LIKE => {
462461 let like = parser. parse_object_name ( false ) . ok ( ) ;
463462 builder = builder. like ( like) ;
464- break ;
465463 }
466464 Keyword :: CLUSTER => {
467465 parser. expect_keyword_is ( Keyword :: BY ) ?;
@@ -587,7 +585,7 @@ pub fn parse_create_table(
587585 builder = builder. columns ( columns) . constraints ( constraints) ;
588586 }
589587 Token :: EOF => {
590- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
588+ if ! builder. has_schema_info ( ) {
591589 return Err ( ParserError :: ParserError (
592590 "unexpected end of input" . to_string ( ) ,
593591 ) ) ;
@@ -596,7 +594,7 @@ pub fn parse_create_table(
596594 break ;
597595 }
598596 Token :: SemiColon => {
599- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
597+ if ! builder. has_schema_info ( ) {
600598 return Err ( ParserError :: ParserError (
601599 "unexpected end of input" . to_string ( ) ,
602600 ) ) ;
Original file line number Diff line number Diff line change @@ -996,13 +996,18 @@ fn test_snowflake_create_iceberg_table_without_location() {
996996}
997997
998998#[ test]
999- fn test_snowflake_create_table_as ( ) {
1000- // Test additional options after AS (query)
999+ fn test_snowflake_create_table_trailing_options ( ) {
10011000 snowflake ( )
10021001 . parse_sql_statements (
10031002 "CREATE TEMP TABLE dst AS (SELECT * FROM src) ON COMMIT PRESERVE ROWS" ,
10041003 )
10051004 . 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 ( ) ;
10061011}
10071012
10081013#[ test]
You can’t perform that action at this time.
0 commit comments