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
4 changes: 3 additions & 1 deletion prqlc/prqlc/src/sql/gen_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ fn try_into_between(expr: rq::Expr, ctx: &mut Context) -> Result<Option<sql_ast:

// We need for the values on each arm to be the same; e.g. x
// > 3 and x < 5
if a_l == b_l {
// Compare only `kind` (not `span`) since the same column
// referenced at two source positions has different spans.
if a_l.kind == b_l.kind {
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a_l.kind == b_l.kind moves the kind field out of a_l/b_l, so a_l can’t be passed to translate_operand(a_l, ...) afterward (partial move). Compare by reference instead (e.g., borrow the fields) or compare the underlying CId directly for ColumnRef to avoid moving the expressions.

Suggested change
if a_l.kind == b_l.kind {
if &a_l.kind == &b_l.kind {

Copilot uses AI. Check for mistakes.
return Ok(Some(sql_ast::Expr::Between {
expr: Box::new(
translate_operand(a_l, true, 0, Associativity::Both, ctx)?
Expand Down
16 changes: 16 additions & 0 deletions prqlc/prqlc/tests/integration/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,22 @@ fn test_precedence_division() {
");
}

#[test]
fn test_between_optimization() {
// Regression test: >= and <= on same column should produce BETWEEN
assert_snapshot!(compile(r#"
from t
filter (a >= 5 && a <= 10)
"#).unwrap(), @r"
SELECT
*
FROM
t
WHERE
a BETWEEN 5 AND 10
");
}

#[test]
fn test_precedence_01() {
assert_snapshot!((compile(r###"
Expand Down
Loading