Skip to content
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

Binding Vec to SELECT IN with SQLite #656

Closed
alucryd opened this issue Aug 26, 2020 · 5 comments
Closed

Binding Vec to SELECT IN with SQLite #656

alucryd opened this issue Aug 26, 2020 · 5 comments

Comments

@alucryd
Copy link

alucryd commented Aug 26, 2020

Would it possible to support binding Vecs to SELECT IN queries in SQLite ? Right now I'm formatting the query on te fly but it would be nice to use a prepared statement for these queries as well.

@servonlewis
Copy link

I'm stuck on this too. For the life of me cannot find a way to query do an IN query.

@Charles-Johnson
Copy link

I am able to pass a Vec<String> that's been .join(",")ed as a parameter to FIND_IN_SET for MySQL which works with the query! macro. Maybe you could do a similar thing with LIKE for SQLite.

@alucryd
Copy link
Author

alucryd commented Sep 9, 2020

Thanks for the suggestion, but that sounds even more hacky than what I'm currently doing, and I'm still not sure this would be using a prepared statement :/

@alun
Copy link

alun commented Sep 27, 2020

plus one here

I'm trying to send multi row update in Postgres with using something like:

        // let strategy_id:String;
        // let order_ids: Vec<String>;
        sqlx::query(
          r#"
          UPDATE orders
          SET strategy_id = $1
          WHERE order_id IN ($2)
          "#,
        )
        .bind(&strategy_id)
        .bind(order_ids)
        .execute(&mut tx)
        .await?;

I'm getting

Error: error returned from database: operator does not exist: character varying = text[]

Tried to scan the source code, didn't find any examples of binding a list (vec) in a SQL statement like this.

UPD:

with Postgres you are able to UNNEST an array which solves my issue 🔥

        sqlx::query(
          r#"
          UPDATE orders
          SET strategy_id = $1
          WHERE order_id IN (SELECT * FROM UNNEST($2))
          "#,
        )
        .bind(&strategy_id)
        .bind(order_ids)
        .execute(&mut tx)
        .await?

@abonander
Copy link
Collaborator

We have an open proposal to make this work, I'm closing this as duplicate: #875

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants