New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL `is` and query params #1733

Closed
kamek-pf opened this Issue May 25, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@kamek-pf

kamek-pf commented May 25, 2018

I'm playing with sql_query, here's the structure I'm trying to deserialize :

#[derive(Debug, QueryableByName)]
#[table_name = "some_table"]
struct User {
    id: i32,
    some_bool: bool,
}

Rust query looks like this :

let users: Vec<User> = sql_query(include_str!("test.sql"))
    .bind::<Bool, _>(true)
    .get_results(&cn)?;

SQL query looks like this :

select id, some_bool from some_table where some_bool = $1

Everything works fine with the above query, the following however, doesn't work :

select id, some_bool from some_table where some_bool is $1

I get a DatabaseError(__Unknown, "syntax error at or near \"$1\"")

Hardcoding the value works though :

select id, some_bool from some_table where some_bool is true

@weiznich weiznich added the question label May 25, 2018

@weiznich

This comment has been minimized.

Contributor

weiznich commented May 25, 2018

Diesel basically passes the raw sql string without any change to the database, so this seems to be a restriction in postgresql itself or libpq. (So nothing diesel could do much about).
From looking at the postgres operator overview it seems that there are only specific arguments are supported after is (and therefore no bind).

(For future questions: Our Gitter room is a better place to ask questions 😉)

@weiznich weiznich closed this May 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment