Closed jawj closed 1 year ago
The query doesn't contain any information about what the type of $1
should be, so it looks like postgres defaults to text
. You could edit the query to specify the type with e.g. SELECT $1::BOOLEAN
or use https://docs.rs/postgres/latest/postgres/struct.Client.html#method.prepare_typed to specify the parameter type.
OK, many thanks.
I'm very new to Rust, so apologies in advance if I've missed something obvious here. I'm trying to run dynamic queries created from JSON data, and I just can't seem to figure out what's going wrong.
Here's the key bit of code:
This compiles and runs, and when the query params are all strings (e.g. the incoming JSON is
{"query":"SELECT $1","params":["xyz"]}
) it all works fine. But any non-string query param makes it blow up.For example,
{"query":"SELECT $1","params":[123]}
blows up with:Similarly,
{"query":"SELECT $1","params":[true]}
gives:And
{"query":"SELECT $1","params":[null]}
:I don't understand why it's apparently trying to convert to the Postgres type
text
: that's not what I want or thought I was asking for. Any hints very much appreciated.