@@ -10189,15 +10189,19 @@ fn parse_trailing_comma() {
10189
10189
"Expected: column name or constraint definition, found: )" . to_string( )
10190
10190
)
10191
10191
) ;
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
+ ) ;
10192
10200
}
10193
10201
10194
10202
#[ test]
10195
10203
fn 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 ( ) ) ;
10201
10205
10202
10206
trailing_commas. one_statement_parses_to (
10203
10207
"SELECT album_id, name, FROM track" ,
@@ -10210,20 +10214,14 @@ fn parse_projection_trailing_comma() {
10210
10214
10211
10215
trailing_commas. verified_stmt ( "SELECT DISTINCT ON (album_id) name FROM track" ) ;
10212
10216
10217
+ let unsupported_dialects = all_dialects_where ( |d| {
10218
+ !d. supports_projection_trailing_commas ( ) && !d. supports_trailing_commas ( )
10219
+ } ) ;
10213
10220
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" )
10216
10223
. 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( ) )
10227
10225
) ;
10228
10226
}
10229
10227
@@ -13061,6 +13059,33 @@ fn parse_overlaps() {
13061
13059
verified_stmt ( "SELECT (DATE '2016-01-10', DATE '2016-02-01') OVERLAPS (DATE '2016-01-20', DATE '2016-02-10')" ) ;
13062
13060
}
13063
13061
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
+
13064
13089
#[ test]
13065
13090
fn test_trailing_commas_in_from ( ) {
13066
13091
let dialects = all_dialects_where ( |d| d. supports_from_trailing_commas ( ) ) ;
0 commit comments