Skip to content

Commit 1823d05

Browse files
fix: pr comments
1 parent 053b251 commit 1823d05

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

src/ast/query.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ pub struct IlikeSelectItem {
529529

530530
impl fmt::Display for IlikeSelectItem {
531531
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
532-
write!(f, "ILIKE '{}'", self.pattern)?;
532+
write!(
533+
f,
534+
"ILIKE '{}'",
535+
value::escape_single_quote_string(&self.pattern)
536+
)?;
533537
Ok(())
534538
}
535539
}

src/parser/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8780,9 +8780,10 @@ impl<'a> Parser<'a> {
87808780
} else {
87818781
None
87828782
};
8783-
let opt_exclude = if dialect_of!(self is GenericDialect | DuckDbDialect | SnowflakeDialect)
8783+
let opt_exclude = if !opt_ilike.is_some()
8784+
&& dialect_of!(self is GenericDialect | DuckDbDialect | SnowflakeDialect)
87848785
{
8785-
self.parse_optional_select_item_exclude(opt_ilike.is_some())?
8786+
self.parse_optional_select_item_exclude()?
87868787
} else {
87878788
None
87888789
};
@@ -8818,8 +8819,12 @@ impl<'a> Parser<'a> {
88188819
&mut self,
88198820
) -> Result<Option<IlikeSelectItem>, ParserError> {
88208821
let opt_ilike = if self.parse_keyword(Keyword::ILIKE) {
8821-
let pattern = self.parse_literal_string()?;
8822-
Some(IlikeSelectItem { pattern })
8822+
let next_token = self.next_token();
8823+
let pattern = match next_token.token {
8824+
Token::SingleQuotedString(s) => Ok(s),
8825+
_ => self.expected("single quoted string", next_token),
8826+
};
8827+
Some(IlikeSelectItem { pattern: pattern? })
88238828
} else {
88248829
None
88258830
};
@@ -8831,12 +8836,8 @@ impl<'a> Parser<'a> {
88318836
/// If it is not possible to parse it, will return an option.
88328837
pub fn parse_optional_select_item_exclude(
88338838
&mut self,
8834-
opt_ilike: bool,
88358839
) -> Result<Option<ExcludeSelectItem>, ParserError> {
88368840
let opt_exclude = if self.parse_keyword(Keyword::EXCLUDE) {
8837-
if opt_ilike {
8838-
return Err(ParserError::ParserError("Unexpected EXCLUDE".to_string()));
8839-
}
88408841
if self.consume_token(&Token::LParen) {
88418842
let columns =
88428843
self.parse_comma_separated(|parser| parser.parse_identifier(false))?;

tests/sqlparser_snowflake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,11 +1629,11 @@ fn test_select_wildcard_with_ilike() {
16291629
}
16301630

16311631
#[test]
1632-
fn test_select_wildcard_with_ilike_non_literal() {
1633-
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE %id FROM tbl"#);
1632+
fn test_select_wildcard_with_ilike_double_quote() {
1633+
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE "%id" FROM tbl"#);
16341634
assert_eq!(
16351635
res.unwrap_err().to_string(),
1636-
"sql parser error: Expected literal string, found: %"
1636+
"sql parser error: Expected single quoted string, found: \"%id\""
16371637
);
16381638
}
16391639

@@ -1651,6 +1651,6 @@ fn test_select_wildcard_with_ilike_replace() {
16511651
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE '%id%' EXCLUDE col FROM tbl"#);
16521652
assert_eq!(
16531653
res.unwrap_err().to_string(),
1654-
"sql parser error: Unexpected EXCLUDE"
1654+
"sql parser error: Expected end of statement, found: EXCLUDE"
16551655
);
16561656
}

0 commit comments

Comments
 (0)