Why does PooledConn::exec return only one row #323
-
Hi, #[derive(Debug)]
#[allow(non_snake_case)]
struct EdRow {
MESS_NR: Option<f64>,
TAG_MITTEL: Option<f64>,
}
impl FromRow for EdRow {
fn from_row_opt(mut row: Row) -> core::result::Result<Self, FromRowError>
where Self: Sized {
Ok(
EdRow {
MESS_NR: row.take("MESS_NR"),
TAG_MITTEL: row.take("TAG_MITTEL"),
})
}
}
[...]
let _ppids = "1401,1874";
let statement = conn.prep("SELECT MESS_NR, SUM(TAG_MITTEL) as TAG_MITTEL from t2022.ed where MESS_NR in (:ppids) group by MESS_NR").unwrap();
let result_set = conn.exec(statement, params!("ppids" => _ppids)).unwrap();
dbg!(&result_set); This returns the following result_set:
But there should be two rows because I want results for ppid 1401 and 1874. [...]
let _ppids = "1401,1874";
let statement = conn.prep("SELECT MESS_NR, SUM(TAG_MITTEL) as TAG_MITTEL from t2022.ed where MESS_NR = 1874 or MESS_NR = 1401 and Datum not in (:ppids) group by MESS_NR").unwrap();
let result_set = conn.exec(statement, params!("ppids" => _ppids)).unwrap();
dbg!(&result_set); And the result was as expected, one row for each supplied ID.
Executing the following query in HeidiSQL or some other DB-Tool will also return both rows: SELECT MESS_NR, AVG(TAG_MITTEL) AS TAG_MITTEL from t2022.ed where MESS_NR in (1401,1874) group by MESS_NR; So why does |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It seems that using an |
Beta Was this translation helpful? Give feedback.
-
Hi. Prepared statements (whether params are named or positional) are not string substitution. Mysql server will replace each parameter with corresponding value taken from the given params. I.e. in your case server will execute |
Beta Was this translation helpful? Give feedback.
Hi.
Prepared statements (whether params are named or positional) are not string substitution. Mysql server will replace each parameter with corresponding value taken from the given params. I.e. in your case server will execute
in ('1401,1874')
(notin (1401,1874)
).