SeaQL/sea-orm · error

Failed to get numeric

Error message

Failed to get numeric

What it means

This panic is raised by `.expect("Failed to get numeric")` in ProxyRow for PostgreSQL (src/driver/sqlx_postgres.rs:595), in the `with-bigdecimal` feature branch. For NUMERIC columns the driver decodes `Option<bigdecimal::BigDecimal>`; if sqlx cannot convert the value into BigDecimal the expect panics. Frequently caused by precision/scale values sqlx's BigDecimal codec can't represent, or the column not really being numeric.

Source

Thrown at src/driver/sqlx_postgres.rs:595

                        ),
                        #[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

  1. Ensure `with-bigdecimal` on sea-orm matches the sqlx `decimal-num-bigdecimal` feature and rebuild.
  2. Check the actual column type and cast in SQL (`col::numeric`) or reduce precision/scale of the column definition.
  3. Pin matching sea-orm/sqlx versions; numeric decoding changed between releases.
  4. Try the alternative decoder: disable `with-bigdecimal` and use `with-rust_decimal` if your values fit rust_decimal's 96-bit range.
  5. Log with RUST_LOG=sqlx=debug to see the underlying decode error before the panic.

Example fix

// Cargo.toml: feature mismatch
// before
sea-orm = { version = "1", features = ["sqlx-postgres", "with-bigdecimal"] }
sqlx = { version = "0.8", features = ["postgres"] } // missing bigdecimal support
// after
sqlx = { version = "0.8", features = ["postgres", "decimal-num-bigdecimal"] }
Defensive patterns

Strategy: validation

Validate before calling

// Confirm feature alignment before compiling reads:
// cargo tree -i bigdecimal  -- ensure one version shared by sea-orm and sqlx
// Check column scale fits: SELECT numeric_scale FROM information_schema.columns
//   WHERE table_name=$1 AND column_name=$2;

Type guard

fn is_numeric_col(c: &ProxyColumn) -> bool {
    c.ty == "NUMERIC"
}

Try / catch

std::panic::catch_unwind(|| read_row(row))
    .map_err(|p| DbErr::Custom(format!("numeric decode panic: {p:?}")))?;

Prevention

When it happens

Trigger: Reading a NUMERIC column with extreme precision/scale (e.g. NUMERIC(100,50)) that bigdecimal's conversion rejects, a value stored as float8/text under a numeric type name, or `with-bigdecimal` enabled on sea-orm but sqlx compiled without the bigdecimal feature.

Common situations: Mixed feature flags between sea-orm and sqlx in Cargo.toml, decimal values from other clients with more digits than the decoder supports, schema drift where a numeric column was changed to double precision, or sqlx version mismatch.

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


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/27da81e7553337b6. Report an issue: GitHub.