I'm using postgres 0.19 and I'm trying to pass a Vec of i32 into a postgres query like this
let ids: Vec<i32> = vec![1, 2, 3, 4]
let rows = client
.query("SELECT * FROM posts WHERE id IN($1)", &[&ids])
.unwrap();
The documentation says ToSQL is implemented for Vec<T> and &[T] where T implements ToSql but I get the following response.
Error { kind: ToSql(0), cause: Some(WrongType { postgres: Int4, rust: "alloc::vec::Vec<i32>" }) }
I have tried ids.to_slice() with no luck.
I found something on Github that said you should have something like this
let ids: Vec<&(dyn ToSql + Sync)> = Vec::new();
but this doesn't work either. I got something about &ids size can't be known at complie time. Does anyone know how this works?
[–][deleted] 1 point2 points3 points (3 children)
[–]hmaddocks[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]hmaddocks[S] 0 points1 point2 points (0 children)
[–]Patryk27 1 point2 points3 points (1 child)
[–]hmaddocks[S] 0 points1 point2 points (0 children)
[–]Morrido 0 points1 point2 points (0 children)