SeaQL/sea-orm · error

Failed to get big integer array

Error message

Failed to get big integer array

What it means

Panic while decoding a Postgres bigint array column (BIGINT[]/BIGSERIAL[]/INT8[]) in ProxyRow conversion: `row.try_get::<Option<Vec<i64>>, _>(ordinal).expect("Failed to get big integer array")`. A NULL array is tolerated by the Option target, so failure means an element could not be decoded as i64 — typically NULL elements inside the array (decode requires `Vec<Option<i64>>`) — or the runtime data is not an i64 array despite the reported type name.

Source

Thrown at sea-orm-sync/src/driver/sqlx_postgres.rs:499

                        "INT[]" | "SERIAL[]" | "INT4[]" => Value::Array(
                            sea_query::ArrayType::Int,
                            row.try_get::<Option<Vec<i32>>, _>(c.ordinal())
                                .expect("Failed to get integer array")
                                .map(|vals: Vec<i32>| {
                                    Box::new(
                                        vals.into_iter().map(|val| Value::Int(Some(val))).collect(),
                                    )
                                }),
                        ),

                        "BIGINT" | "BIGSERIAL" | "INT8" => Value::BigInt(
                            row.try_get(c.ordinal()).expect("Failed to get big integer"),
                        ),
                        #[cfg(feature = "postgres-array")]
                        "BIGINT[]" | "BIGSERIAL[]" | "INT8[]" => Value::Array(
                            sea_query::ArrayType::BigInt,
                            row.try_get::<Option<Vec<i64>>, _>(c.ordinal())
                                .expect("Failed to get big integer array")
                                .map(|vals: Vec<i64>| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::BigInt(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "FLOAT4" | "REAL" => {
                            Value::Float(row.try_get(c.ordinal()).expect("Failed to get float"))
                        }
                        #[cfg(feature = "postgres-array")]
                        "FLOAT4[]" | "REAL[]" => Value::Array(
                            sea_query::ArrayType::Float,
                            row.try_get::<Option<Vec<f32>>, _>(c.ordinal())
                                .expect("Failed to get float array")
                                .map(|vals| {

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Decode elements as Option: `row.try_get::<Option<Vec<Option<i64>>>, _>(c.ordinal())` and map None elements explicitly.
  2. Strip NULLs in SQL: `array_remove(col, NULL::bigint)` or `COALESCE(array_agg(x), ARRAY[]::bigint[])`.
  3. Cast to plain bigint[] (`col::bigint[]`) to bypass DOMAIN arrays.
  4. Verify element type with `pg_typeof` and fix schema or query accordingly.
  5. Enforce NOT NULL on the source column when the model expects plain i64 elements.

Example fix

// before (panics on NULL elements)
"BIGINT[]" | "BIGSERIAL[]" | "INT8[]" => Value::Array(ArrayType::BigInt,
    row.try_get::<Option<Vec<i64>>, _>(c.ordinal()).expect("Failed to get big integer array")...),
// after (SQL-side guard)
// SELECT array_remove(col, NULL::bigint) AS col FROM t;
"BIGINT[]" | "BIGSERIAL[]" | "INT8[]" => Value::Array(ArrayType::BigInt,
    row.try_get::<Option<Vec<i64>>, _>(c.ordinal()).expect("Failed to get big integer array")...),
Defensive patterns

Strategy: try-catch

Validate before calling

// SELECT bool_and(e IS NOT NULL) FROM unnest(col::bigint[]) AS e;
// or in SQL: SELECT array_remove(col, NULL::bigint) AS col FROM t;

Type guard

fn as_i64_array(row: &ProxyRow, col: &str) -> Option<Vec<i64>> {
    match row.value(col) {
        Some(Value::Array(ArrayType::BigInt, vals)) => Some(
            vals.iter().filter_map(|v| match v {
                Value::BigInt(Some(x)) => Some(*x),
                _ => None,
            }).collect(),
        ),
        _ => None,
    }
}

Try / catch

let result = std::panic::catch_unwind(|| proxy_row_get_i64_array(&row, "ids"));
match result {
    Ok(v) => v,
    Err(_) => Vec::new(), // or re-query with array_remove(col, NULL::bigint)
}

Prevention

When it happens

Trigger: Selecting an int8 array containing NULL elements (e.g. `array_agg(bigint_col)` over rows with NULLs); array-of-DOMAIN over bigint; a view or custom type reporting BIGINT[] whose elements are not i64-decodable.

Common situations: Aggregating nullable bigint id columns into arrays; unnest/merge pipelines producing sparse arrays; schema migrations altering element types while reported names lag; Postgres DOMAIN arrays over bigint.

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/5ec044372f965890. Report an issue: GitHub.