mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
provide ILIKE support
This introduces support for ILIKE and NOT ILIKE. ILIKE is the case-insensitive variant of LIKE. Systems such as Postgres, Redshift, and Snowflake provide this variant.[1][2][3] [1] https://www.postgresql.org/docs/7.3/functions-matching.html [2] https://docs.aws.amazon.com/redshift/latest/dg/r_patternmatching_condition_like.html [3] https://docs.snowflake.com/en/sql-reference/functions/ilike.html
This commit is contained in:
parent
1e87ab8e22
commit
a9e6f77d62
5 changed files with 62 additions and 1 deletions
|
@ -687,6 +687,51 @@ fn parse_like() {
|
|||
chk(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_ilike() {
|
||||
fn chk(negated: bool) {
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}ILIKE '%a'",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
op: if negated {
|
||||
BinaryOperator::NotILike
|
||||
} else {
|
||||
BinaryOperator::ILike
|
||||
},
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
},
|
||||
select.selection.unwrap()
|
||||
);
|
||||
|
||||
// This statement tests that LIKE and NOT LIKE have the same precedence.
|
||||
// This was previously mishandled (#81).
|
||||
let sql = &format!(
|
||||
"SELECT * FROM customers WHERE name {}ILIKE '%a' IS NULL",
|
||||
if negated { "NOT " } else { "" }
|
||||
);
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::IsNull(Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("name"))),
|
||||
op: if negated {
|
||||
BinaryOperator::NotILike
|
||||
} else {
|
||||
BinaryOperator::ILike
|
||||
},
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString("%a".to_string()))),
|
||||
})),
|
||||
select.selection.unwrap()
|
||||
);
|
||||
}
|
||||
chk(false);
|
||||
chk(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_in_list() {
|
||||
fn chk(negated: bool) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue