在Rust-postgres中定义并传递固定精度数字(Postgres中的十进制或数字)的正确方法是什么?
$state.transitionTo($state.current, $stateParams, {
reload: true, inherit: false, notify: true
});
余额和冻结余额均为transaction.execute("INSERT INTO commons_account(
display_name, blocked, balance, blocked_balance, password, salt)
VALUES ($1, $2, $3, $4, $5, $6);", &[&"bob", &false, &0, &0, &"dfasdfsa", &"dfsdsa"]).unwrap();
,运行此代码会出现此错误
numeric
答案 0 :(得分:2)
struct Float64(f64);
impl ToSql for Float64 { // Or a fixed-precision type.
to_sql_checked!();
fn to_sql<W: Write + ?Sized>(&self, _: &Type, mut w: &mut W, _: &SessionInfo) -> Result<IsNull> {
let num = 0;
w.write_f64::<BigEndian>(num)?;
*self = Float64(num);
Ok(IsNull::No)
}
accepts!(Type::Numeric);
}
不在was removed in 3.0中。
您需要自己实现特征ToSql,例如:
int.Parse("Steve")