SeaQL/sea-orm · error

Failed to get integer array

Error message

Failed to get integer array

What it means

Panic while decoding a Postgres integer array column (INT[]/SERIAL[]/INT4[]) in ProxyRow conversion: `row.try_get::<Option<Vec<i32>>, _>(ordinal).expect("Failed to get integer array")`. A NULL array is handled by the Option target, so the failure means an element could not be decoded as i32 — classically NULL elements inside the array (requiring `Vec<Option<i32>>`) — or the runtime data is not an i32 array despite the reported type name.

Source

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

                            row.try_get::<Option<Vec<i16>>, _>(c.ordinal())
                                .expect("Failed to get small integer array")
                                .map(|vals: Vec<i16>| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::SmallInt(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "INT" | "SERIAL" | "INT4" => {
                            Value::Int(row.try_get(c.ordinal()).expect("Failed to get integer"))
                        }
                        #[cfg(feature = "postgres-array")]
                        "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()

View on GitHub (pinned to e29bcd1b41)

Solutions

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

Example fix

// before (panics on NULL elements)
"INT[]" | "SERIAL[]" | "INT4[]" => Value::Array(ArrayType::Int,
    row.try_get::<Option<Vec<i32>>, _>(c.ordinal()).expect("Failed to get integer array")...),
// after (SQL-side guard)
// SELECT array_remove(col, NULL::int) AS col FROM t;
"INT[]" | "SERIAL[]" | "INT4[]" => Value::Array(ArrayType::Int,
    row.try_get::<Option<Vec<i32>>, _>(c.ordinal()).expect("Failed to get integer array")...),
Defensive patterns

Strategy: try-catch

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Selecting an int4 array with NULL elements (e.g. `array_agg(nullable_col)`); array-of-DOMAIN over integer; a view/custom type reporting INT[] whose elements aren't i32-decodable; truncated numeric text stored where the type name lies.

Common situations: Aggregating nullable FK/id columns into arrays; unnest/merge patterns producing sparse arrays; schema migration changed element type while type-info still reports INT[]; Postgres DOMAIN arrays.

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/542cfbadbcabee52. Report an issue: GitHub.