Allow trailing comma in CREATE TABLE

At least MSSQL supports it, not sure about others.
This commit is contained in:
Nickolay Ponomarev 2019-05-05 21:18:31 +03:00
parent 8569a61fd0
commit 0407ed2b57
2 changed files with 12 additions and 11 deletions

View file

@ -898,17 +898,12 @@ impl Parser {
} else { } else {
return self.expected("column name or constraint definition", self.peek_token()); return self.expected("column name or constraint definition", self.peek_token());
} }
match self.next_token() { let comma = self.consume_token(&Token::Comma);
Some(Token::Comma) => {} if self.consume_token(&Token::RParen) {
Some(Token::RParen) => { // allow a trailing comma, even though it's not in standard
break; break;
} } else if !comma {
other => { return self.expected("',' or ')' after column definition", self.peek_token());
return parser_err!(format!(
"Expected ',' or ')' after column definition but found {:?}",
other
));
}
} }
} }

View file

@ -688,6 +688,12 @@ fn parse_create_table() {
} }
} }
#[test]
fn parse_create_table_trailing_comma() {
let sql = "CREATE TABLE foo (bar int,)";
all_dialects().one_statement_parses_to(sql, "CREATE TABLE foo (bar int)");
}
#[test] #[test]
fn parse_create_external_table() { fn parse_create_external_table() {
let sql = "CREATE EXTERNAL TABLE uk_cities (\ let sql = "CREATE EXTERNAL TABLE uk_cities (\