Add support for the MATCH and REGEXP binary operators (#1840)

This commit is contained in:
Ophir LOJKINE 2025-05-09 01:48:23 +02:00 committed by GitHub
parent 6cd237ea43
commit 2182f7ea71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 1 deletions

View file

@ -562,6 +562,36 @@ fn test_dollar_identifier_as_placeholder() {
}
}
#[test]
fn test_match_operator() {
assert_eq!(
sqlite().verified_expr("col MATCH 'pattern'"),
Expr::BinaryOp {
op: BinaryOperator::Match,
left: Box::new(Expr::Identifier(Ident::new("col"))),
right: Box::new(Expr::Value(
(Value::SingleQuotedString("pattern".to_string())).with_empty_span()
))
}
);
sqlite().verified_only_select("SELECT * FROM email WHERE email MATCH 'fts5'");
}
#[test]
fn test_regexp_operator() {
assert_eq!(
sqlite().verified_expr("col REGEXP 'pattern'"),
Expr::BinaryOp {
op: BinaryOperator::Regexp,
left: Box::new(Expr::Identifier(Ident::new("col"))),
right: Box::new(Expr::Value(
(Value::SingleQuotedString("pattern".to_string())).with_empty_span()
))
}
);
sqlite().verified_only_select(r#"SELECT count(*) FROM messages WHERE msg_text REGEXP '\d+'"#);
}
fn sqlite() -> TestedDialects {
TestedDialects::new(vec![Box::new(SQLiteDialect {})])
}