let amount: i32 = 20;
let amount_daily: f32 = 4.2;
add.sql
amount INT NOT NULL,
amount_daily REAL NOT NULL,
SQLX query_file!("add.sql", amount, amount_daily)
Cargo.toml
sqlx = { version = "^0.7.4", features = [
"runtime-tokio-native-tls",
"postgres",
"macros",
"chrono",
"bigdecimal",
] }
bigdecimal = { version = "^0.4.3", features = ["serde"] }
Error
the trait bound `bigdecimal::BigDecimal: Encode<'_, Postgres>` is not satisfied
the following other types implement trait `Encode<'q, DB>`:
<bool as Encode<'q, sqlx::Any>>
<bool as Encode<'_, Postgres>>
<i8 as Encode<'_, Postgres>>
<i16 as Encode<'q, sqlx::Any>>
<i16 as Encode<'_, Postgres>>
<i32 as Encode<'q, sqlx::Any>>
<i32 as Encode<'_, Postgres>>
<i64 as Encode<'q, sqlx::Any>>
and 41 others
required for `&bigdecimal::BigDecimal` to implement `Encode<'_, Postgres>`rustcClick for full compiler diagnostic
mod.rs(398, 9): Actual error occurred here
mod.rs(398, 9): Error originated from macro call here
the trait bound `bigdecimal::BigDecimal: sqlx::Type<Postgres>` is not satisfied
the following other types implement trait `sqlx::Type<DB>`:
<bool as sqlx::Type<Postgres>>
<bool as sqlx::Type<sqlx::Any>>
<i8 as sqlx::Type<Postgres>>
<i16 as sqlx::Type<Postgres>>
<i16 as sqlx::Type<sqlx::Any>>
<i32 as sqlx::Type<Postgres>>
<i32 as sqlx::Type<sqlx::Any>>
<i64 as sqlx::Type<Postgres>>
and 52 others
required for `&bigdecimal::BigDecimal` to implement `sqlx::Type<Postgres>`
1 redundant requirement hidden
required for `&&bigdecimal::BigDecimal` to implement `sqlx::Type<Postgres>`rustcClick for full compiler diagnostic
mod.rs(398, 9): Actual error occurred here
mod.rs(398, 9): Error originated from macro call here
arguments.rs(19, 53): required by a bound in `sqlx::Arguments::add`
Note that sqlx depends on bigdecimal 0.3, whereas you import the incompatible bigdecimal 0.4, which could be the reason for the error message that the trait isn't implemented for bigdecimal::BigDecimal (as the BigDecimal from bigdecimal 0.4 is a distinct type from BigDecimal from bigdecimal 0.3, which should implement Encode).
Thanks
I changed the version to 0.3 & now getting different error.
the trait bound `BigDecimal: From<f32>` is not satisfied
the following other types implement trait `From<T>`:
<BigDecimal as From<i8>>
<BigDecimal as From<i16>>
<BigDecimal as From<i32>>
<BigDecimal as From<i64>>
<BigDecimal as From<u8>>
<BigDecimal as From<u16>>
<BigDecimal as From<u32>>
<BigDecimal as From<u64>>
and 2 othersrustcClick for full compiler diagnostic
bigdecimal
// size = 40 (0x28), align = 0x8
pub struct BigDecimal
A big decimal type.
Why sqlx does not re-export the bigdecimal which they are using in their package.
The column data type is REAL.
Still sqlx asking for Bigdecimal.
So what I did is Bigdecimal::from(amount_daily) but even without convert & just amount_daily both are not working.
With Bigdecimal::try_from(amount_daily) I am getting this same error
Error
the trait bound `Result<BigDecimal, Infallible>: Encode<'_, Postgres>` is not satisfied
the following other types implement trait `Encode<'q, DB>`:
<bool as Encode<'q, sqlx::Any>>
<bool as Encode<'_, Postgres>>
<i8 as Encode<'_, Postgres>>
<i16 as Encode<'q, sqlx::Any>>
<i16 as Encode<'_, Postgres>>
<i32 as Encode<'q, sqlx::Any>>
<i32 as Encode<'_, Postgres>>
<i64 as Encode<'q, sqlx::Any>>
and 41 othersrustcClick for full compiler diagnostic
mod.rs(398, 9): Actual error occurred here
mod.rs(398, 9): Error originated from macro call here
the trait bound `Result<BigDecimal, bigdecimal::ParseBigDecimalError>: Encode<'_, Postgres>` is not satisfied
the following other types implement trait `Encode<'q, DB>`:
<bool as Encode<'q, sqlx::Any>>
<bool as Encode<'_, Postgres>>
<i8 as Encode<'_, Postgres>>
<i16 as Encode<'q, sqlx::Any>>
<i16 as Encode<'_, Postgres>>
<i32 as Encode<'q, sqlx::Any>>
<i32 as Encode<'_, Postgres>>
<i64 as Encode<'q, sqlx::Any>>
and 41 othersrustcClick for full compiler diagnostic
mod.rs(398, 9): Actual error occurred here
mod.rs(398, 9): Error originated from macro call here
the trait bound `Result<BigDecimal, Infallible>: sqlx::Type<Postgres>` is not satisfied
the following other types implement trait `sqlx::Type<DB>`:
<bool as sqlx::Type<Postgres>>
<bool as sqlx::Type<sqlx::Any>>
<i8 as sqlx::Type<Postgres>>
<i16 as sqlx::Type<Postgres>>
<i16 as sqlx::Type<sqlx::Any>>
<i32 as sqlx::Type<Postgres>>
<i32 as sqlx::Type<sqlx::Any>>
<i64 as sqlx::Type<Postgres>>
and 52 others
required for `&Result<BigDecimal, Infallible>` to implement `sqlx::Type<Postgres>`rustcClick for full compiler diagnostic
mod.rs(398, 9): Actual error occurred here
mod.rs(398, 9): Error originated from macro call here
arguments.rs(19, 53): required by a bound in `sqlx::Arguments::add`
the trait bound `Result<BigDecimal, bigdecimal::ParseBigDecimalError>: sqlx::Type<Postgres>` is not satisfied
the following other types implement trait `sqlx::Type<DB>`:
<bool as sqlx::Type<Postgres>>
<bool as sqlx::Type<sqlx::Any>>
<i8 as sqlx::Type<Postgres>>
<i16 as sqlx::Type<Postgres>>
<i16 as sqlx::Type<sqlx::Any>>
<i32 as sqlx::Type<Postgres>>
<i32 as sqlx::Type<sqlx::Any>>
<i64 as sqlx::Type<Postgres>>
and 52 others
required for `&Result<BigDecimal, bigdecimal::ParseBigDecimalError>` to implement `sqlx::Type<Postgres>`rustcClick for full compiler diagnostic
mod.rs(398, 9): Actual error occurred here
mod.rs(398, 9): Error originated from macro call here
arguments.rs(19, 53): required by a bound in `sqlx::Arguments::add`
sqlx::types::BigDecimal
This one found
But ToPrimitive can not found