Issue using f32/f64 parameters in db.execute() inserts (Rust + PostgreSQL)

โš“ Rust    ๐Ÿ“… 2025-11-03    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 7      

surdeus

Hi 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

Read full topic

๐Ÿท๏ธ Rust_feed