From 4cb10c0a1b7436c5bdfd6a70888e6b7bda31751b Mon Sep 17 00:00:00 2001 From: "aleksei.p" Date: Wed, 25 Sep 2024 07:57:06 +0200 Subject: [PATCH] update --- src/parser/mod.rs | 23 +++++++++++------------ tests/sqlparser_snowflake.rs | 34 +++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 104fc2e73..d623e882d 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -8197,26 +8197,25 @@ impl<'a> Parser<'a> { && self.parse_keyword(Keyword::OPTIONS) { self.prev_token(); - let option = ColumnOption::Options(self.parse_options(Keyword::OPTIONS)?); - options.push(option); + if let Some(option) = self.parse_optional_column_option()? { + options.push(option); + } }; if dialect_of!(self is SnowflakeDialect | GenericDialect) && self.parse_keyword(Keyword::COMMENT) { - let next_token = self.next_token(); - let option = match next_token.token { - Token::SingleQuotedString(str) => ColumnOption::Comment(str), - _ => self.expected("string literal", next_token)?, - }; - options.push(option); + self.prev_token(); + if let Some(option) = self.parse_optional_column_option()? { + options.push(option); + } }; - let data_type = if dialect_of!(self is ClickHouseDialect) { - Some(self.parse_data_type()?) + let options = if !options.is_empty() { + Some(options) } else { None }; - let options = if !options.is_empty() { - Some(options) + let data_type = if dialect_of!(self is ClickHouseDialect) { + Some(self.parse_data_type()?) } else { None }; diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 81a5cc7f6..15ce08b2a 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -2401,26 +2401,34 @@ fn parse_use() { } } +#[test] +fn view_comment_option_should_be_after_column_list() { + snowflake_and_generic() + .verified_stmt("CREATE OR REPLACE VIEW v (a) COMMENT = 'Comment' AS SELECT a FROM t"); +} + #[test] fn parse_view_column_descriptions() { - let sql = "CREATE OR REPLACE VIEW v (a COMMENT 'Comment of field') COMMENT = 'Comment of view' AS SELECT a FROM table1 AS o"; + let sql = + "CREATE OR REPLACE VIEW v (a COMMENT 'Comment', b) AS SELECT a, b FROM table1"; match snowflake_and_generic().verified_stmt(sql) { - Statement::CreateView { - name, - columns, - comment, - .. - } => { + Statement::CreateView { name, columns, .. } => { assert_eq!(name.to_string(), "v"); - assert_eq!(comment, Some("Comment of view".to_string())); assert_eq!( columns, - vec![ViewColumnDef { - name: Ident::new("a"), - data_type: None, - options: Some(vec![ColumnOption::Comment("Comment of field".to_string())]), - },] + vec![ + ViewColumnDef { + name: Ident::new("a"), + data_type: None, + options: Some(vec![ColumnOption::Comment("Comment".to_string())]), + }, + ViewColumnDef { + name: Ident::new("b"), + data_type: None, + options: None, + } + ] ); } _ => unreachable!(),