@@ -10189,15 +10189,19 @@ fn parse_trailing_comma() {
1018910189 "Expected: column name or constraint definition, found: )" . to_string( )
1019010190 )
1019110191 ) ;
10192+
10193+ let unsupported_dialects = all_dialects_where ( |d| !d. supports_trailing_commas ( ) ) ;
10194+ assert_eq ! (
10195+ unsupported_dialects
10196+ . parse_sql_statements( "SELECT * FROM track ORDER BY milliseconds," )
10197+ . unwrap_err( ) ,
10198+ ParserError :: ParserError ( "Expected: an expression, found: EOF" . to_string( ) )
10199+ ) ;
1019210200}
1019310201
1019410202#[ test]
1019510203fn parse_projection_trailing_comma ( ) {
10196- // Some dialects allow trailing commas only in the projection
10197- let trailing_commas = TestedDialects :: new ( vec ! [
10198- Box :: new( SnowflakeDialect { } ) ,
10199- Box :: new( BigQueryDialect { } ) ,
10200- ] ) ;
10204+ let trailing_commas = all_dialects_where ( |d| d. supports_projection_trailing_commas ( ) ) ;
1020110205
1020210206 trailing_commas. one_statement_parses_to (
1020310207 "SELECT album_id, name, FROM track" ,
@@ -10210,20 +10214,14 @@ fn parse_projection_trailing_comma() {
1021010214
1021110215 trailing_commas. verified_stmt ( "SELECT DISTINCT ON (album_id) name FROM track" ) ;
1021210216
10217+ let unsupported_dialects = all_dialects_where ( |d| {
10218+ !d. supports_projection_trailing_commas ( ) && !d. supports_trailing_commas ( )
10219+ } ) ;
1021310220 assert_eq ! (
10214- trailing_commas
10215- . parse_sql_statements( "SELECT * FROM track ORDER BY milliseconds, " )
10221+ unsupported_dialects
10222+ . parse_sql_statements( "SELECT album_id, name, FROM track" )
1021610223 . unwrap_err( ) ,
10217- ParserError :: ParserError ( "Expected: an expression, found: EOF" . to_string( ) )
10218- ) ;
10219-
10220- assert_eq ! (
10221- trailing_commas
10222- . parse_sql_statements( "CREATE TABLE employees (name text, age int,)" )
10223- . unwrap_err( ) ,
10224- ParserError :: ParserError (
10225- "Expected: column name or constraint definition, found: )" . to_string( )
10226- ) ,
10224+ ParserError :: ParserError ( "Expected an expression, found: FROM" . to_string( ) )
1022710225 ) ;
1022810226}
1022910227
@@ -13061,6 +13059,33 @@ fn parse_overlaps() {
1306113059 verified_stmt ( "SELECT (DATE '2016-01-10', DATE '2016-02-01') OVERLAPS (DATE '2016-01-20', DATE '2016-02-10')" ) ;
1306213060}
1306313061
13062+ #[ test]
13063+ fn parse_column_definition_trailing_commas ( ) {
13064+ let dialects = all_dialects_where ( |d| d. supports_column_definition_trailing_commas ( ) ) ;
13065+
13066+ dialects. one_statement_parses_to ( "CREATE TABLE T (x INT64,)" , "CREATE TABLE T (x INT64)" ) ;
13067+ dialects. one_statement_parses_to (
13068+ "CREATE TABLE T (x INT64, y INT64, )" ,
13069+ "CREATE TABLE T (x INT64, y INT64)" ,
13070+ ) ;
13071+ dialects. one_statement_parses_to (
13072+ "CREATE VIEW T (x, y, ) AS SELECT 1" ,
13073+ "CREATE VIEW T (x, y) AS SELECT 1" ,
13074+ ) ;
13075+
13076+ let unsupported_dialects = all_dialects_where ( |d| {
13077+ !d. supports_projection_trailing_commas ( ) && !d. supports_trailing_commas ( )
13078+ } ) ;
13079+ assert_eq ! (
13080+ unsupported_dialects
13081+ . parse_sql_statements( "CREATE TABLE employees (name text, age int,)" )
13082+ . unwrap_err( ) ,
13083+ ParserError :: ParserError (
13084+ "Expected: column name or constraint definition, found: )" . to_string( )
13085+ ) ,
13086+ ) ;
13087+ }
13088+
1306413089#[ test]
1306513090fn test_trailing_commas_in_from ( ) {
1306613091 let dialects = all_dialects_where ( |d| d. supports_from_trailing_commas ( ) ) ;
0 commit comments