Skip to content

Commit 6da8828

Browse files
authored
feat: support tailing commas on snowflake dialect. (apache#1205)
1 parent 17ef71e commit 6da8828

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/parser/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,14 +2946,15 @@ impl<'a> Parser<'a> {
29462946

29472947
/// Parse a comma-separated list of 1+ SelectItem
29482948
pub fn parse_projection(&mut self) -> Result<Vec<SelectItem>, ParserError> {
2949-
// BigQuery allows trailing commas, but only in project lists
2949+
// BigQuery and Snowflake allow trailing commas, but only in project lists
29502950
// e.g. `SELECT 1, 2, FROM t`
29512951
// https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#trailing_commas
2952+
// https://docs.snowflake.com/en/release-notes/2024/8_11#select-supports-trailing-commas
29522953
//
29532954
// This pattern could be captured better with RAII type semantics, but it's quite a bit of
29542955
// code to add for just one case, so we'll just do it manually here.
29552956
let old_value = self.options.trailing_commas;
2956-
self.options.trailing_commas |= dialect_of!(self is BigQueryDialect);
2957+
self.options.trailing_commas |= dialect_of!(self is BigQueryDialect | SnowflakeDialect);
29572958

29582959
let ret = self.parse_comma_separated(|p| p.parse_select_item());
29592960
self.options.trailing_commas = old_value;

tests/sqlparser_snowflake.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,3 +1536,8 @@ fn parse_comma_outer_join() {
15361536
"SELECT t1.c1, t2.c2 FROM t1, t2 WHERE t1.c1 = t2.c2 (+)",
15371537
);
15381538
}
1539+
1540+
#[test]
1541+
fn test_sf_trailing_commas() {
1542+
snowflake().verified_only_select_with_canonical("SELECT 1, 2, FROM t", "SELECT 1, 2 FROM t");
1543+
}

0 commit comments

Comments
 (0)