mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-30 06:47:17 +00:00
Add support for the LIKE ANY and ILIKE ANY pattern-matching condition (#1456)
This commit is contained in:
parent
32a126b27c
commit
e849f7f143
3 changed files with 36 additions and 4 deletions
|
|
@ -613,6 +613,9 @@ pub enum Expr {
|
|||
/// `[NOT] LIKE <pattern> [ESCAPE <escape_character>]`
|
||||
Like {
|
||||
negated: bool,
|
||||
// Snowflake supports the ANY keyword to match against a list of patterns
|
||||
// https://docs.snowflake.com/en/sql-reference/functions/like_any
|
||||
any: bool,
|
||||
expr: Box<Expr>,
|
||||
pattern: Box<Expr>,
|
||||
escape_char: Option<String>,
|
||||
|
|
@ -620,6 +623,9 @@ pub enum Expr {
|
|||
/// `ILIKE` (case-insensitive `LIKE`)
|
||||
ILike {
|
||||
negated: bool,
|
||||
// Snowflake supports the ANY keyword to match against a list of patterns
|
||||
// https://docs.snowflake.com/en/sql-reference/functions/like_any
|
||||
any: bool,
|
||||
expr: Box<Expr>,
|
||||
pattern: Box<Expr>,
|
||||
escape_char: Option<String>,
|
||||
|
|
@ -1242,20 +1248,23 @@ impl fmt::Display for Expr {
|
|||
expr,
|
||||
pattern,
|
||||
escape_char,
|
||||
any,
|
||||
} => match escape_char {
|
||||
Some(ch) => write!(
|
||||
f,
|
||||
"{} {}LIKE {} ESCAPE '{}'",
|
||||
"{} {}LIKE {}{} ESCAPE '{}'",
|
||||
expr,
|
||||
if *negated { "NOT " } else { "" },
|
||||
if *any { "ANY " } else { "" },
|
||||
pattern,
|
||||
ch
|
||||
),
|
||||
_ => write!(
|
||||
f,
|
||||
"{} {}LIKE {}",
|
||||
"{} {}LIKE {}{}",
|
||||
expr,
|
||||
if *negated { "NOT " } else { "" },
|
||||
if *any { "ANY " } else { "" },
|
||||
pattern
|
||||
),
|
||||
},
|
||||
|
|
@ -1264,20 +1273,23 @@ impl fmt::Display for Expr {
|
|||
expr,
|
||||
pattern,
|
||||
escape_char,
|
||||
any,
|
||||
} => match escape_char {
|
||||
Some(ch) => write!(
|
||||
f,
|
||||
"{} {}ILIKE {} ESCAPE '{}'",
|
||||
"{} {}ILIKE {}{} ESCAPE '{}'",
|
||||
expr,
|
||||
if *negated { "NOT " } else { "" },
|
||||
if *any { "ANY" } else { "" },
|
||||
pattern,
|
||||
ch
|
||||
),
|
||||
_ => write!(
|
||||
f,
|
||||
"{} {}ILIKE {}",
|
||||
"{} {}ILIKE {}{}",
|
||||
expr,
|
||||
if *negated { "NOT " } else { "" },
|
||||
if *any { "ANY " } else { "" },
|
||||
pattern
|
||||
),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2749,6 +2749,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 +2759,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))?,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue