@@ -3552,8 +3552,13 @@ fn parse_create_table_clone() {
35523552
35533553#[ test]
35543554fn parse_create_table_trailing_comma ( ) {
3555- let sql = "CREATE TABLE foo (bar int,)" ;
3556- all_dialects ( ) . one_statement_parses_to ( sql, "CREATE TABLE foo (bar INT)" ) ;
3555+ let dialect = TestedDialects {
3556+ dialects : vec ! [ Box :: new( DuckDbDialect { } ) ] ,
3557+ options : None ,
3558+ } ;
3559+
3560+ let sql = "CREATE TABLE foo (bar int,);" ;
3561+ dialect. one_statement_parses_to ( sql, "CREATE TABLE foo (bar INT)" ) ;
35573562}
35583563
35593564#[ test]
@@ -4418,7 +4423,7 @@ fn parse_window_clause() {
44184423 ORDER BY C3";
44194424 verified_only_select ( sql) ;
44204425
4421- let sql = "SELECT from mytable WINDOW window1 AS window2" ;
4426+ let sql = "SELECT * from mytable WINDOW window1 AS window2" ;
44224427 let dialects = all_dialects_except ( |d| d. is :: < BigQueryDialect > ( ) || d. is :: < GenericDialect > ( ) ) ;
44234428 let res = dialects. parse_sql_statements ( sql) ;
44244429 assert_eq ! (
@@ -8846,9 +8851,11 @@ fn parse_non_latin_identifiers() {
88468851
88478852#[ test]
88488853fn parse_trailing_comma ( ) {
8854+ // At the moment, Duck DB is the only dialect that allows
8855+ // trailing commas anywhere in the query
88498856 let trailing_commas = TestedDialects {
8850- dialects : vec ! [ Box :: new( GenericDialect { } ) ] ,
8851- options : Some ( ParserOptions :: new ( ) . with_trailing_commas ( true ) ) ,
8857+ dialects : vec ! [ Box :: new( DuckDbDialect { } ) ] ,
8858+ options : None ,
88528859 } ;
88538860
88548861 trailing_commas. one_statement_parses_to (
@@ -8866,11 +8873,74 @@ fn parse_trailing_comma() {
88668873 "SELECT DISTINCT ON (album_id) name FROM track" ,
88678874 ) ;
88688875
8876+ trailing_commas. one_statement_parses_to (
8877+ "CREATE TABLE employees (name text, age int,)" ,
8878+ "CREATE TABLE employees (name TEXT, age INT)" ,
8879+ ) ;
8880+
88698881 trailing_commas. verified_stmt ( "SELECT album_id, name FROM track" ) ;
88708882
88718883 trailing_commas. verified_stmt ( "SELECT * FROM track ORDER BY milliseconds" ) ;
88728884
88738885 trailing_commas. verified_stmt ( "SELECT DISTINCT ON (album_id) name FROM track" ) ;
8886+
8887+ // doesn't allow any trailing commas
8888+ let trailing_commas = TestedDialects {
8889+ dialects : vec ! [ Box :: new( GenericDialect { } ) ] ,
8890+ options : None ,
8891+ } ;
8892+
8893+ assert_eq ! (
8894+ trailing_commas
8895+ . parse_sql_statements( "SELECT name, age, from employees;" )
8896+ . unwrap_err( ) ,
8897+ ParserError :: ParserError ( "Expected an expression, found: from" . to_string( ) )
8898+ ) ;
8899+
8900+ assert_eq ! (
8901+ trailing_commas
8902+ . parse_sql_statements( "CREATE TABLE employees (name text, age int,)" )
8903+ . unwrap_err( ) ,
8904+ ParserError :: ParserError (
8905+ "Expected column name or constraint definition, found: )" . to_string( )
8906+ )
8907+ ) ;
8908+ }
8909+
8910+ #[ test]
8911+ fn parse_projection_trailing_comma ( ) {
8912+ // Some dialects allow trailing commas only in the projection
8913+ let trailing_commas = TestedDialects {
8914+ dialects : vec ! [ Box :: new( SnowflakeDialect { } ) , Box :: new( BigQueryDialect { } ) ] ,
8915+ options : None ,
8916+ } ;
8917+
8918+ trailing_commas. one_statement_parses_to (
8919+ "SELECT album_id, name, FROM track" ,
8920+ "SELECT album_id, name FROM track" ,
8921+ ) ;
8922+
8923+ trailing_commas. verified_stmt ( "SELECT album_id, name FROM track" ) ;
8924+
8925+ trailing_commas. verified_stmt ( "SELECT * FROM track ORDER BY milliseconds" ) ;
8926+
8927+ trailing_commas. verified_stmt ( "SELECT DISTINCT ON (album_id) name FROM track" ) ;
8928+
8929+ assert_eq ! (
8930+ trailing_commas
8931+ . parse_sql_statements( "SELECT * FROM track ORDER BY milliseconds," )
8932+ . unwrap_err( ) ,
8933+ ParserError :: ParserError ( "Expected an expression:, found: EOF" . to_string( ) )
8934+ ) ;
8935+
8936+ assert_eq ! (
8937+ trailing_commas
8938+ . parse_sql_statements( "CREATE TABLE employees (name text, age int,)" )
8939+ . unwrap_err( ) ,
8940+ ParserError :: ParserError (
8941+ "Expected column name or constraint definition, found: )" . to_string( )
8942+ ) ,
8943+ ) ;
88748944}
88758945
88768946#[ test]
0 commit comments