Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ pub fn parse_create_stage(
parser.expect_token(&Token::Eq)?;
comment = Some(match parser.next_token().token {
Token::SingleQuotedString(word) => Ok(word),
Token::DollarQuotedString(word) => Ok(word.value),
_ => parser.expected("a comment statement", parser.peek_token()),
}?)
}
Expand Down
20 changes: 13 additions & 7 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5323,6 +5323,7 @@ impl<'a> Parser<'a> {
let next_token = self.next_token();
match next_token.token {
Token::SingleQuotedString(str) => Some(str),
Token::DollarQuotedString(str) => Some(str.value),
_ => self.expected("string literal", next_token)?,
}
} else {
Expand Down Expand Up @@ -6926,14 +6927,16 @@ impl<'a> Parser<'a> {
let comment = if self.parse_keyword(Keyword::COMMENT) {
let has_eq = self.consume_token(&Token::Eq);
let next_token = self.next_token();
match next_token.token {
Token::SingleQuotedString(str) => Some(if has_eq {
CommentDef::WithEq(str)
} else {
CommentDef::WithoutEq(str)
}),
let comment = match next_token.token {
Token::SingleQuotedString(str) => str,
Token::DollarQuotedString(str) => str.value,
_ => self.expected("comment", next_token)?,
}
};
Some(if has_eq {
CommentDef::WithEq(comment)
} else {
CommentDef::WithoutEq(comment)
})
} else {
None
};
Expand Down Expand Up @@ -7078,6 +7081,9 @@ impl<'a> Parser<'a> {
let next_token = self.next_token();
match next_token.token {
Token::SingleQuotedString(value, ..) => Ok(Some(ColumnOption::Comment(value))),
Token::DollarQuotedString(value, ..) => {
Ok(Some(ColumnOption::Comment(value.value)))
}
_ => self.expected("string", next_token),
}
} else if self.parse_keyword(Keyword::NULL) {
Expand Down
15 changes: 15 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,21 @@ fn parse_sf_create_or_replace_with_comment_for_snowflake() {
}
}

#[test]
fn parse_sf_create_table_or_view_with_dollar_quoted_comment() {
// Snowflake transforms dollar quoted comments into a common comment in DDL representation of creation
snowflake()
.one_statement_parses_to(
r#"CREATE OR REPLACE TEMPORARY VIEW foo.bar.baz ("COL_1" COMMENT $$comment 1$$) COMMENT = $$view comment$$ AS (SELECT 1)"#,
r#"CREATE OR REPLACE TEMPORARY VIEW foo.bar.baz ("COL_1" COMMENT 'comment 1') COMMENT = 'view comment' AS (SELECT 1)"#
);

snowflake().one_statement_parses_to(
r#"CREATE TABLE my_table (a STRING COMMENT $$comment 1$$) COMMENT = $$table comment$$"#,
r#"CREATE TABLE my_table (a STRING COMMENT 'comment 1') COMMENT = 'table comment'"#,
);
}

#[test]
fn test_sf_derived_table_in_parenthesis() {
// Nesting a subquery in an extra set of parentheses is non-standard,
Expand Down