-
Notifications
You must be signed in to change notification settings - Fork 605
Add support for the LIKE ANY and ILIKE ANY pattern-matching condition #1456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2734,6 +2734,10 @@ impl<'a> Parser<'a> { | |
let regexp = self.parse_keyword(Keyword::REGEXP); | ||
let rlike = self.parse_keyword(Keyword::RLIKE); | ||
if regexp || rlike { | ||
if self.parse_keyword(Keyword::ANY) { | ||
self.prev_token(); | ||
return self.expected("pattern after RLIKE or REGEXP", self.peek_token()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah not sure I followed this part, we don't seem to take any action for when parsing ANY is successful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only point of this condition was to add a meaningful error message when parsing incorrect syntax, for example: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed in the latest commit. |
||
Ok(Expr::RLike { | ||
negated, | ||
expr: Box::new(expr), | ||
|
@@ -2749,6 +2753,7 @@ impl<'a> Parser<'a> { | |
} else if self.parse_keyword(Keyword::LIKE) { | ||
Ok(Expr::Like { | ||
negated, | ||
any: self.parse_keyword(Keyword::ANY), | ||
expr: Box::new(expr), | ||
pattern: Box::new( | ||
self.parse_subexpr(self.dialect.prec_value(Precedence::Like))?, | ||
|
@@ -2758,6 +2763,7 @@ impl<'a> Parser<'a> { | |
} else if self.parse_keyword(Keyword::ILIKE) { | ||
Ok(Expr::ILike { | ||
negated, | ||
any: self.parse_keyword(Keyword::ANY), | ||
expr: Box::new(expr), | ||
pattern: Box::new( | ||
self.parse_subexpr(self.dialect.prec_value(Precedence::Like))?, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2162,6 +2162,19 @@ fn test_select_wildcard_with_ilike_replace() { | |
); | ||
} | ||
|
||
#[test] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the syntax support was added for all dialects (I think seems reasonable), can we move the test to sqlparser_common.rs so that they run against all dialects? |
||
fn test_select_where_with_like_or_ilike_any() { | ||
snowflake().verified_stmt(r#"SELECT * FROM x WHERE a ILIKE ANY '%abc%'"#); | ||
snowflake().verified_stmt(r#"SELECT * FROM x WHERE a LIKE ANY '%abc%'"#); | ||
snowflake().verified_stmt(r#"SELECT * FROM x WHERE a ILIKE ANY ('%Jo%oe%', 'T%e')"#); | ||
snowflake().verified_stmt(r#"SELECT * FROM x WHERE a LIKE ANY ('%Jo%oe%', 'T%e')"#); | ||
let res = snowflake().parse_sql_statements(r#"SELECT * FROM x WHERE a RLIKE ANY '%abc%'"#); | ||
assert_eq!( | ||
res.unwrap_err().to_string(), | ||
"sql parser error: Expected: pattern after RLIKE or REGEXP, found: ANY" | ||
); | ||
} | ||
|
||
#[test] | ||
fn first_value_ignore_nulls() { | ||
snowflake().verified_only_select(concat!( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a link to the snowflake doc where the syntax is mentioned? It would help with context for someone that comes across it in the codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in the latest commit