sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

`ValueTypeErr` crash when using `ArrayType::Decimal` that contains `None` entries

Open gitmalong opened this issue 1 year ago • 0 comments

panicked at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sea-query-0.30.7/src/value.rs:256:27:
called `Result::unwrap()` on an `Err` value: ValueTypeErr

// let entries: Vec<Option<Decimal>> = .. ;
let decimals: Vec<Value> = entries
        .iter()
        .map(|x| Value::Decimal(x.map(|x| Box::new(x))))
        .collect();
 let decimals = Value::Array(ArrayType::Decimal, Some(Box::new(volume_base_asset)));

 self.db
  .execute(Statement::from_sql_and_values(
      DatabaseBackend::Postgres,
      r#"
      INSERT INTO table (
          volume
      )
      SELECT 
          unnest($1::NUMERIC[])
      "#,
      [
          decimals
      ],
  ))
  .await
  .unwrap();

gitmalong avatar Jul 09 '24 20:07 gitmalong