SeaQL/sea-orm · error
Failed to get numeric
Error message
Failed to get numeric
What it means
This panic comes from `.expect("Failed to get numeric")` in `ProxyRow`, decoding a Postgres NUMERIC column as `Option<bigdecimal::BigDecimal>` when the `with-bigdecimal` feature is enabled. It fires when sqlx cannot decode the value as BigDecimal -- usually the runtime column type is not actually `numeric` (e.g. it was ALTERed to float8 or text), or the crate's bigdecimal/sqlx versions are incompatible so the decode impl rejects the wire format. The `expect` escalates this to a panic.
Source
Thrown at sea-orm-sync/src/driver/sqlx_postgres.rs:582
),
#[cfg(feature = "postgres-array")]
"BYTEA[]" => Value::Array(
sea_query::ArrayType::Bytes,
row.try_get::<Option<Vec<Vec<u8>>>, _>(c.ordinal())
.expect("Failed to get bytes array")
.map(|vals| {
Box::new(
vals.into_iter()
.map(|val| Value::Bytes(Some(val)))
.collect(),
)
}),
),
#[cfg(feature = "with-bigdecimal")]
"NUMERIC" => Value::BigDecimal(
row.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())
.expect("Failed to get numeric"),
),
#[cfg(all(
feature = "with-rust_decimal",
not(feature = "with-bigdecimal")
))]
"NUMERIC" => {
Value::Decimal(row.try_get(c.ordinal()).expect("Failed to get numeric"))
}
#[cfg(all(feature = "with-bigdecimal", feature = "postgres-array"))]
"NUMERIC[]" => Value::Array(
sea_query::ArrayType::BigDecimal,
row.try_get::<Option<Vec<bigdecimal::BigDecimal>>, _>(c.ordinal())
.expect("Failed to get numeric array")
.map(|vals| {
Box::new(
vals.into_iter()
.map(|val| Value::BigDecimal(Some(val)))View on GitHub (pinned to e29bcd1b41)
Solutions
- Confirm the actual column type is NUMERIC (`\d table`); ALTER it back or map the entity field to f64/Decimal to match the real type.
- Align `bigdecimal` and `sqlx` versions with those required by your sea-orm version (check sea-orm's Cargo.toml for the exact feature-mapped versions).
- Cast in the query: `SELECT col::NUMERIC AS col` to guarantee a numeric reaches the driver.
- Alternatively switch to `with-rust_decimal` (the fallback branch in this code) and map the field to rust_decimal::Decimal.
Example fix
// before: column altered to float8 but entity still uses BigDecimal pub rate: BigDecimal, // after: match the actual column type pub rate: f64,
Defensive patterns
Strategy: validation
Validate before calling
let row: (String, ) = sqlx::query_as(
"SELECT data_type FROM information_schema.columns WHERE table_name = $1 AND column_name = $2"
).bind("my_table").bind("rate").fetch_one(&db).await?;
assert_eq!(row.0, "numeric", "rate must be NUMERIC, got {}", row.0);
// Also verify bigdecimal version matches sea-orm's requirement in Cargo.toml Type guard
fn as_bigdecimal(v: &sea_orm::Value) -> Option<bigdecimal::BigDecimal> {
match v {
sea_orm::Value::BigDecimal(d) => d.clone(),
_ => None,
}
} Prevention
- Pin the `bigdecimal` crate to the exact version your sea-orm release depends on (check its Cargo.toml).
- Use BigDecimal only for true NUMERIC columns; f64/Double for float8.
- Run ALTER COLUMN ... TYPE changes through migrations that also update entities.
- Cast (::NUMERIC) in raw SQL when reading numerics through views.
When it happens
Trigger: Any SeaORM query returning a NUMERIC column that cannot be decoded into BigDecimal: column type altered away from numeric, a domain type over numeric with unexpected OIDs, or a version mismatch between `bigdecimal` and `sqlx` crates after a dependency update.
Common situations: `ALTER COLUMN ... TYPE DOUBLE PRECISION` for performance while the model still expects a decimal. Cargo dependency drift: sea-orm pinned to bigdecimal 0.3 while sqlx expects 0.4 (feature mismatch). Reading numeric columns through views that cast to float.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Failed to get numeric
- Failed to get numeric array
- Failed to get float
- Failed to get float array
- Failed to get double
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/8a93300d2e29505f.
Report an issue: GitHub.