From 6da8828c1b664a87f8ffe0cd68609aec046f436c Mon Sep 17 00:00:00 2001 From: yassun7010 <47286750+yassun7010@users.noreply.github.com> Date: Wed, 10 Apr 2024 05:19:27 +0900 Subject: [PATCH] feat: support tailing commas on snowflake dialect. (#1205) --- src/parser/mod.rs | 5 +++-- tests/sqlparser_snowflake.rs | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 57e24d218..48eaed92c 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -2946,14 +2946,15 @@ impl<'a> Parser<'a> { /// Parse a comma-separated list of 1+ SelectItem pub fn parse_projection(&mut self) -> Result, ParserError> { - // BigQuery allows trailing commas, but only in project lists + // BigQuery and Snowflake allow trailing commas, but only in project lists // e.g. `SELECT 1, 2, FROM t` // https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#trailing_commas + // https://docs.snowflake.com/en/release-notes/2024/8_11#select-supports-trailing-commas // // This pattern could be captured better with RAII type semantics, but it's quite a bit of // code to add for just one case, so we'll just do it manually here. let old_value = self.options.trailing_commas; - self.options.trailing_commas |= dialect_of!(self is BigQueryDialect); + self.options.trailing_commas |= dialect_of!(self is BigQueryDialect | SnowflakeDialect); let ret = self.parse_comma_separated(|p| p.parse_select_item()); self.options.trailing_commas = old_value; diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 49b440506..880129f82 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -1536,3 +1536,8 @@ fn parse_comma_outer_join() { "SELECT t1.c1, t2.c2 FROM t1, t2 WHERE t1.c1 = t2.c2 (+)", ); } + +#[test] +fn test_sf_trailing_commas() { + snowflake().verified_only_select_with_canonical("SELECT 1, 2, FROM t", "SELECT 1, 2 FROM t"); +}