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 @@ -559,12 +559,10 @@ pub fn parse_create_table(
559559 Keyword :: CLONE => {
560560 let clone = parser. parse_object_name ( false ) . ok ( ) ;
561561 builder = builder. clone_clause ( clone) ;
562- break ;
563562 }
564563 Keyword :: LIKE => {
565564 let like = parser. parse_object_name ( false ) . ok ( ) ;
566565 builder = builder. like ( like) ;
567- break ;
568566 }
569567 Keyword :: CLUSTER => {
570568 parser. expect_keyword_is ( Keyword :: BY ) ?;
@@ -690,7 +688,7 @@ pub fn parse_create_table(
690688 builder = builder. columns ( columns) . constraints ( constraints) ;
691689 }
692690 Token :: EOF => {
693- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
691+ if ! builder. has_schema_info ( ) {
694692 return Err ( ParserError :: ParserError (
695693 "unexpected end of input" . to_string ( ) ,
696694 ) ) ;
@@ -699,7 +697,7 @@ pub fn parse_create_table(
699697 break ;
700698 }
701699 Token :: SemiColon => {
702- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
700+ if ! builder. has_schema_info ( ) {
703701 return Err ( ParserError :: ParserError (
704702 "unexpected end of input" . to_string ( ) ,
705703 ) ) ;
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