@@ -10192,15 +10192,19 @@ fn parse_trailing_comma() {
10192
10192
"Expected: column name or constraint definition, found: )" . to_string( )
10193
10193
)
10194
10194
) ;
10195
+
10196
+ let unsupported_dialects = all_dialects_where ( |d| !d. supports_trailing_commas ( ) ) ;
10197
+ assert_eq ! (
10198
+ unsupported_dialects
10199
+ . parse_sql_statements( "SELECT * FROM track ORDER BY milliseconds," )
10200
+ . unwrap_err( ) ,
10201
+ ParserError :: ParserError ( "Expected: an expression, found: EOF" . to_string( ) )
10202
+ ) ;
10195
10203
}
10196
10204
10197
10205
#[ test]
10198
10206
fn parse_projection_trailing_comma ( ) {
10199
- // Some dialects allow trailing commas only in the projection
10200
- let trailing_commas = TestedDialects :: new ( vec ! [
10201
- Box :: new( SnowflakeDialect { } ) ,
10202
- Box :: new( BigQueryDialect { } ) ,
10203
- ] ) ;
10207
+ let trailing_commas = all_dialects_where ( |d| d. supports_projection_trailing_commas ( ) ) ;
10204
10208
10205
10209
trailing_commas. one_statement_parses_to (
10206
10210
"SELECT album_id, name, FROM track" ,
@@ -10213,20 +10217,14 @@ fn parse_projection_trailing_comma() {
10213
10217
10214
10218
trailing_commas. verified_stmt ( "SELECT DISTINCT ON (album_id) name FROM track" ) ;
10215
10219
10220
+ let unsupported_dialects = all_dialects_where ( |d| {
10221
+ !d. supports_projection_trailing_commas ( ) && !d. supports_trailing_commas ( )
10222
+ } ) ;
10216
10223
assert_eq ! (
10217
- trailing_commas
10218
- . parse_sql_statements( "SELECT * FROM track ORDER BY milliseconds, " )
10224
+ unsupported_dialects
10225
+ . parse_sql_statements( "SELECT album_id, name, FROM track" )
10219
10226
. unwrap_err( ) ,
10220
- ParserError :: ParserError ( "Expected: an expression, found: EOF" . to_string( ) )
10221
- ) ;
10222
-
10223
- assert_eq ! (
10224
- trailing_commas
10225
- . parse_sql_statements( "CREATE TABLE employees (name text, age int,)" )
10226
- . unwrap_err( ) ,
10227
- ParserError :: ParserError (
10228
- "Expected: column name or constraint definition, found: )" . to_string( )
10229
- ) ,
10227
+ ParserError :: ParserError ( "Expected an expression, found: FROM" . to_string( ) )
10230
10228
) ;
10231
10229
}
10232
10230
@@ -13064,6 +13062,33 @@ fn parse_overlaps() {
13064
13062
verified_stmt ( "SELECT (DATE '2016-01-10', DATE '2016-02-01') OVERLAPS (DATE '2016-01-20', DATE '2016-02-10')" ) ;
13065
13063
}
13066
13064
13065
+ #[ test]
13066
+ fn parse_column_definition_trailing_commas ( ) {
13067
+ let dialects = all_dialects_where ( |d| d. supports_column_definition_trailing_commas ( ) ) ;
13068
+
13069
+ dialects. one_statement_parses_to ( "CREATE TABLE T (x INT64,)" , "CREATE TABLE T (x INT64)" ) ;
13070
+ dialects. one_statement_parses_to (
13071
+ "CREATE TABLE T (x INT64, y INT64, )" ,
13072
+ "CREATE TABLE T (x INT64, y INT64)" ,
13073
+ ) ;
13074
+ dialects. one_statement_parses_to (
13075
+ "CREATE VIEW T (x, y, ) AS SELECT 1" ,
13076
+ "CREATE VIEW T (x, y) AS SELECT 1" ,
13077
+ ) ;
13078
+
13079
+ let unsupported_dialects = all_dialects_where ( |d| {
13080
+ !d. supports_projection_trailing_commas ( ) && !d. supports_trailing_commas ( )
13081
+ } ) ;
13082
+ assert_eq ! (
13083
+ unsupported_dialects
13084
+ . parse_sql_statements( "CREATE TABLE employees (name text, age int,)" )
13085
+ . unwrap_err( ) ,
13086
+ ParserError :: ParserError (
13087
+ "Expected: column name or constraint definition, found: )" . to_string( )
13088
+ ) ,
13089
+ ) ;
13090
+ }
13091
+
13067
13092
#[ test]
13068
13093
fn test_trailing_commas_in_from ( ) {
13069
13094
let dialects = all_dialects_where ( |d| d. supports_from_trailing_commas ( ) ) ;
0 commit comments