Issue using f32/f64 parameters in db.execute() inserts (Rust + PostgreSQL)
โ Rust ๐ 2025-11-03 ๐ค surdeus ๐๏ธ 7Hi everyone,
Iโm running into a strange issue when trying to insert floating-point parameters f32 f64 using db.execute() in Rust (with the postgres crate).
Hereโs a simplified example for testing
fn doIncluirTeste(db: &mut Client) {
/*
select * from teste2
delete from teste2
create table teste2
(codigo int,
cst varchar(20),
RedutorIBS numeric(18,2))
*/
let codigo: i32 = 15;
let cst: &str = "000";
let valor: f32 = 0.34;
// This works:
// db.execute("Insert Into teste2 (Codigo, CST) VALUES ($1, $2)", &[&codigo, &cst])
// This also works:
// db.execute("Insert Into teste2 (Codigo, CST, RedutorIBS) VALUES ($1, $2, 0.43)", &[&codigo, &cst])
// But this does NOT work:
match db.execute(
"Insert Into teste2 (Codigo, CST, RedutorIBS) VALUES ($1, $2, $3)",
&[&codigo, &cst, &valor],
) {
Ok(res) => println!("{}", res),
Err(err) => println!("{}", err),
}
}
I'm receiving 'error serializing parameter 2
2 posts - 2 participants
๐ท๏ธ Rust_feed