Skip to navigation
Convert Postgres numeric type to a rust type
28.03.23
Example, you have a column total as numeric and you like to convert it to a rust type: `let total: PgNumeric = i.get("total");` 1. Cargo: pg_bigdecimal = "0.1.5" 2. Code: use postgres::{*}; use std::collections::HashMap; use pg_bigdecimal::{PgNumeric, BigDecimal}; let mut client = Client::connect("host=x.x.x.x port=5432 user=foo password=foo dbname=bar", NoTls).expect("failed"); let rows = client.query(sql,&[])?; for i in rows { let total: PgNumeric = i.get("total"); }
https://docs.rs/pg_bigdecimal/0.1.5/pg_bigdecimal/struct.PgNumeric.html
Reply
Anonymous
Information Epoch 1742254503
Silence is golden.
Home
Notebook
Contact us