Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 在rust postgres中使用固定精度数字的正确方法是什么?_Postgresql_Rust - Fatal编程技术网

Postgresql 在rust postgres中使用固定精度数字的正确方法是什么?

Postgresql 在rust postgres中使用固定精度数字的正确方法是什么?,postgresql,rust,Postgresql,Rust,定义固定精度数字(Postgres中的十进制或数字)并将其传递给rust Postgres中的insert的正确方法是什么 transaction.execute("INSERT INTO commons_account( display_name, blocked, balance, blocked_balance, password, salt) VALUES ($1, $2, $3, $4, $5, $6);", &[&"bo

定义固定精度数字(Postgres中的十进制或数字)并将其传递给rust Postgres中的insert的正确方法是什么

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();
余额和冻结余额都是数值,运行此代码会导致此错误

thread 'test' panicked at 'called `Result::unwrap()` on an `Err` value: WrongType(Numeric)'

Numeric
不在列表中。 您需要自己通过以下方式实现trait-ToSql:

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);
}
structfloat64(f64);
浮点64{//或固定精度类型的impl ToSql。
要检查sql!();
fn to_sql(&self,u:&Type,mut w:&mut w,u:&SessionInfo)->结果{
设num=0;
w、 写入64::(num)?;
*self=64(num);
确定(IsNull::否)
}
接受!(类型::数字);
}

我刚刚发现Rust没有内置的十进制类型,这让一切变得更加复杂difficult@ibrabeicker有,;另见