Skip to content

Commit 24e1283

Browse files
authored
MySQL: Add support for && as boolean AND (#2144)
1 parent 00da3d7 commit 24e1283

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
@@ -1221,6 +1221,11 @@ pub trait Dialect: Debug + Any {
12211221
fn supports_quote_delimited_string(&self) -> bool {
12221222
false
12231223
}
1224+
1225+
/// Returns true if the dialect considers the `&&` operator as a boolean AND operator.
1226+
fn supports_double_ampersand_operator(&self) -> bool {
1227+
false
1228+
}
12241229
}
12251230

12261231
/// 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
@@ -171,6 +171,11 @@ impl Dialect for MySqlDialect {
171171
fn supports_cross_join_constraint(&self) -> bool {
172172
true
173173
}
174+
175+
/// See: <https://dev.mysql.com/doc/refman/8.4/en/expressions.html>
176+
fn supports_double_ampersand_operator(&self) -> bool {
177+
true
178+
}
174179
}
175180

176181
/// `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_double_ampersand_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
@@ -18037,3 +18037,9 @@ fn parse_select_parenthesized_wildcard() {
1803718037
assert_eq!(select2.projection.len(), 1);
1803818038
assert!(matches!(select2.projection[0], SelectItem::Wildcard(_)));
1803918039
}
18040+
18041+
#[test]
18042+
fn parse_overlap_as_bool_and() {
18043+
let dialects = all_dialects_where(|d| d.supports_double_ampersand_operator());
18044+
dialects.one_statement_parses_to("SELECT x && y", "SELECT x AND y");
18045+
}

0 commit comments

Comments
 (0)