Skip to content

Mathematical operations need to wrap in parenthesis #2017

@sgrif

Description

@sgrif

Setup

Versions

  • Rust: any
  • Diesel: any
  • Database: any
  • Operating System any

Feature Flags

  • diesel:

Problem Description

Parenthesis inserted in Rust to override order of operations are lost in the generated SQL. This can also occur when a value is assigned to a local variable. This will at best result in an incorrect value being generated, and at worst will result in a runtime error because of incorrect types (e.g. interval * (integer - integer) is valid but interval * integer - integer is not)

What is the expected output?

14

What is the actual output?

10

Steps to reproduce

fn test(conn: &Connection) {
    let x = select(2.into_sql::<Integer>() * (3.into_sql::<Integer>() + 4))
        .get_result(conn);
    assert_eq!(Ok(14), x);
}

Checklist

  • I have already looked over the issue tracker for similar issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions