Skip to content

Make GenericDialect support trailing commas in projections #1921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dialect/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl Dialect for GenericDialect {
true
}

fn supports_projection_trailing_commas(&self) -> bool {
true
}

fn supports_asc_desc_in_column_definition(&self) -> bool {
true
}
Expand Down
9 changes: 1 addition & 8 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11125,16 +11125,9 @@ fn parse_trailing_comma() {
);
trailing_commas.verified_stmt(r#"SELECT "from" FROM "from""#);

// doesn't allow any trailing commas
// doesn't allow all trailing commas
let trailing_commas = TestedDialects::new(vec![Box::new(GenericDialect {})]);

assert_eq!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we instead change this to use a dialect like postgres that doesnt support trailing commas? thinking that would let us keep the negative test around.

trailing_commas
.parse_sql_statements("SELECT name, age, from employees;")
.unwrap_err(),
ParserError::ParserError("Expected an expression, found: from".to_string())
);

assert_eq!(
trailing_commas
.parse_sql_statements("REVOKE USAGE, SELECT, ON p TO u")
Expand Down