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 @@ -473,12 +473,10 @@ pub fn parse_create_table(
473473 Keyword :: CLONE => {
474474 let clone = parser. parse_object_name ( false ) . ok ( ) ;
475475 builder = builder. clone_clause ( clone) ;
476- break ;
477476 }
478477 Keyword :: LIKE => {
479478 let like = parser. parse_object_name ( false ) . ok ( ) ;
480479 builder = builder. like ( like) ;
481- break ;
482480 }
483481 Keyword :: CLUSTER => {
484482 parser. expect_keyword_is ( Keyword :: BY ) ?;
@@ -604,7 +602,7 @@ pub fn parse_create_table(
604602 builder = builder. columns ( columns) . constraints ( constraints) ;
605603 }
606604 Token :: EOF => {
607- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
605+ if ! builder. has_schema_info ( ) {
608606 return Err ( ParserError :: ParserError (
609607 "unexpected end of input" . to_string ( ) ,
610608 ) ) ;
@@ -613,7 +611,7 @@ pub fn parse_create_table(
613611 break ;
614612 }
615613 Token :: SemiColon => {
616- if builder. columns . is_empty ( ) && builder . query . is_none ( ) {
614+ if ! builder. has_schema_info ( ) {
617615 return Err ( ParserError :: ParserError (
618616 "unexpected end of input" . to_string ( ) ,
619617 ) ) ;
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