Skip to content

Commit 9157ff5

Browse files
committed
MySQL: Add support for && as boolean AND
1 parent 14703f0 commit 9157ff5

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

src/dialect/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,11 @@ pub trait Dialect: Debug + Any {
12161216
fn supports_quote_delimited_string(&self) -> bool {
12171217
false
12181218
}
1219+
1220+
/// Returns true if the dialect considers the `&&` operator as a boolean AND operator.
1221+
fn supports_overlap_as_and_operator(&self) -> bool {
1222+
false
1223+
}
12191224
}
12201225

12211226
/// This represents the operators for which precedence must be defined

src/dialect/mysql.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ impl Dialect for MySqlDialect {
167167
fn supports_cross_join_constraint(&self) -> bool {
168168
true
169169
}
170+
171+
/// See: <https://dev.mysql.com/doc/refman/8.4/en/expressions.html>
172+
fn supports_overlap_as_and_operator(&self) -> bool {
173+
true
174+
}
170175
}
171176

172177
/// `LOCK TABLES`

src/parser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,9 @@ impl<'a> Parser<'a> {
35003500
Token::Overlap if dialect_is!(dialect is PostgreSqlDialect | GenericDialect) => {
35013501
Some(BinaryOperator::PGOverlap)
35023502
}
3503+
Token::Overlap if dialect.supports_overlap_as_and_operator() => {
3504+
Some(BinaryOperator::And)
3505+
}
35033506
Token::CaretAt if dialect_is!(dialect is PostgreSqlDialect | GenericDialect) => {
35043507
Some(BinaryOperator::PGStartsWith)
35053508
}

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17972,3 +17972,9 @@ fn parse_select_parenthesized_wildcard() {
1797217972
assert_eq!(select2.projection.len(), 1);
1797317973
assert!(matches!(select2.projection[0], SelectItem::Wildcard(_)));
1797417974
}
17975+
17976+
#[test]
17977+
fn parse_overlap_as_bool_and() {
17978+
let dialects = all_dialects_where(|d| d.supports_overlap_as_and_operator());
17979+
dialects.one_statement_parses_to("SELECT x && y", "SELECT x AND y");
17980+
}

0 commit comments

Comments
 (0)