Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/dialect/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ impl Dialect for SQLiteDialect {
Precedence::Ampersand => 24,
Precedence::Caret => 23,
Precedence::Pipe | Precedence::Colon | Precedence::PgOther => 22,
// `parse.y` puts LIKE, GLOB, MATCH and REGEXP on the level of `=`
Precedence::Between | Precedence::Eq | Precedence::Like => 20,
Precedence::Is => 17,
// `parse.y` puts IS, LIKE, GLOB, MATCH and REGEXP on the level of `=`
Precedence::Between | Precedence::Eq | Precedence::Like | Precedence::Is => 20,
Precedence::UnaryNot => 15,
Precedence::And => 10,
Precedence::Or => 5,
Expand Down
3 changes: 2 additions & 1 deletion tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,7 @@ fn parse_is_distinct_from_precedence() {
verified_expr("a IS DISTINCT FROM b + 1")
);

// SQLite puts `IS` on the level of `=`, see `parse_is_groups_with_equality`.
assert_eq!(
IsDistinctFrom(
Box::new(Identifier(Ident::new("a"))),
Expand All @@ -2179,7 +2180,7 @@ fn parse_is_distinct_from_precedence() {
right: Box::new(Identifier(Ident::new("c"))),
}),
),
verified_expr("a IS DISTINCT FROM b = c")
all_dialects_except(|d| d.is::<SQLiteDialect>()).verified_expr("a IS DISTINCT FROM b = c")
);

// `NOT` binds more loosely than `IS`, so it applies to the whole comparison.
Expand Down
81 changes: 81 additions & 0 deletions tests/sqlparser_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2349,3 +2349,84 @@ fn parse_unquoted_escape_is_not_an_alias() {
}
sqlite().verified_stmt(r#"SELECT 'a' LIKE 'b' = 0 AS "ESCAPE""#);
}

#[test]
fn parse_is_groups_with_equality() {
let id = |name: &str| Expr::Identifier(Ident::new(name));
let binary = |left: Expr, op: BinaryOperator, right: Expr| Expr::BinaryOp {
left: Box::new(left),
op,
right: Box::new(right),
};
let distinct = |left: Expr, right: Expr| Expr::IsDistinctFrom(Box::new(left), Box::new(right));
let not_distinct =
|left: Expr, right: Expr| Expr::IsNotDistinctFrom(Box::new(left), Box::new(right));
use BinaryOperator::{Eq, Lt, NotEq};

for (sql, expected) in [
(
"a IS DISTINCT FROM b = c",
binary(distinct(id("a"), id("b")), Eq, id("c")),
),
(
"a = b IS DISTINCT FROM c",
distinct(binary(id("a"), Eq, id("b")), id("c")),
),
(
"a IS NOT DISTINCT FROM b <> c",
binary(not_distinct(id("a"), id("b")), NotEq, id("c")),
),
(
"a <> b IS NOT DISTINCT FROM c",
not_distinct(binary(id("a"), NotEq, id("b")), id("c")),
),
(
"a IS DISTINCT FROM b BETWEEN c AND d",
Expr::Between {
expr: Box::new(distinct(id("a"), id("b"))),
negated: false,
low: Box::new(id("c")),
high: Box::new(id("d")),
},
),
(
"a IS DISTINCT FROM b IN (c)",
Expr::In {
expr: Box::new(distinct(id("a"), id("b"))),
target: InTarget::List(vec![id("c")]),
negated: false,
global: false,
},
),
(
"a IS DISTINCT FROM b < c",
distinct(id("a"), binary(id("b"), Lt, id("c"))),
),
(
"a LIKE b IS NULL",
Expr::IsNull {
expr: Box::new(Expr::Like {
negated: false,
any: false,
expr: Box::new(id("a")),
pattern: Box::new(id("b")),
escape_char: None,
}),
syntax: IsNullSyntax::IsNull,
},
),
(
"a IS NULL = b",
binary(
Expr::IsNull {
expr: Box::new(id("a")),
syntax: IsNullSyntax::IsNull,
},
Eq,
id("b"),
),
),
] {
assert_eq!(sqlite().verified_expr(sql), expected, "{sql}");
}
}
Loading