SeaQL/sea-orm · error

Failed to get numeric array

Error message

Failed to get numeric array

What it means

This panic is raised by `.expect("Failed to get numeric array")` in the `with-bigdecimal` + `postgres-array` branch of ProxyRow (src/driver/sqlx_postgres.rs:609). For NUMERIC[] columns the driver decodes `Option<Vec<bigdecimal::BigDecimal>>`; failure of sqlx to decode the array (wrong element type, missing feature, or oversized digits) panics.

Source

Thrown at src/driver/sqlx_postgres.rs:609

                        #[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)))
                                            .collect(),
                                    )
                                }),
                        ),
                        #[cfg(all(
                            feature = "with-rust_decimal",
                            not(feature = "with-bigdecimal"),
                            feature = "postgres-array"
                        ))]
                        "NUMERIC[]" => Value::Array(
                            sea_query::ArrayType::Decimal,
                            row.try_get::<Option<Vec<rust_decimal::Decimal>>, _>(c.ordinal())
                                .expect("Failed to get numeric array")
                                .map(|vals| {

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Enable both `postgres-array` and `with-bigdecimal` on sea-orm and the corresponding sqlx features, then rebuild.
  2. Verify element type (`SELECT array_typeof(col)`) and cast in SQL: `col::numeric[]`.
  3. Pin compatible sea-orm/sqlx versions; numeric-array decoding changed across releases.
  4. Use RUST_LOG=sqlx=debug to reveal the underlying decode error before the expect.
  5. Map the failure to DbErr::Custom with the column ordinal instead of panicking.

Example fix

// Cargo.toml
// before
sea-orm = { version = "1", features = ["sqlx-postgres", "with-bigdecimal"] }
// after
sea-orm = { version = "1", features = ["sqlx-postgres", "with-bigdecimal", "postgres-array"] }
Defensive patterns

Strategy: validation

Validate before calling

// Verify numeric[] element type before reading:
// SELECT array_typeof(col) FROM t LIMIT 1;  -- expect 'numeric'
// Or cast: SELECT col::numeric[] FROM ...

Type guard

fn is_numeric_array_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 NUMERIC[] where elements were produced as float8[] or text[], missing sqlx bigdecimal/arrays feature combination, or array elements with precision that the bigdecimal decoder path in that sqlx version cannot handle.

Common situations: Feature-flag combinations not enabled together (`postgres-array` + bigdecimal), sea-orm/sqlx version skew, schema drift converting numeric[] from other array types, or array_agg over numeric in an sqlx version without that array decode.

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/612270f0cbd27c10. Report an issue: GitHub.