SeaQL/sea-orm · error

Failed to get float array

Error message

Failed to get float array

What it means

This panic comes from `.expect("Failed to get float array")` in `ProxyRow`, where a Postgres column typed FLOAT4[]/REAL[] is decoded as `Option<Vec<f32>>` (behind the `postgres-array` feature). It fires when sqlx cannot decode the array's element type or shape into `Vec<f32>` -- typically because the actual array element OID differs (e.g. the column was changed to FLOAT8[] or a non-float array). Because the code uses `expect`, the failure panics instead of surfacing a driver error.

Source

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

                            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| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::Float(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "FLOAT8" | "DOUBLE PRECISION" => {
                            Value::Double(row.try_get(c.ordinal()).expect("Failed to get double"))
                        }
                        #[cfg(feature = "postgres-array")]
                        "FLOAT8[]" | "DOUBLE PRECISION[]" => Value::Array(
                            sea_query::ArrayType::Double,
                            row.try_get::<Option<Vec<f64>>, _>(c.ordinal())
                                .expect("Failed to get double array")
                                .map(|vals| {

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Check the true column type (`\d table`) and make the entity field type match it exactly (Vec<f32> for float4[], Vec<f64> for float8[]).
  2. Cast in the query to force the element type: `SELECT col::REAL[] AS col`.
  3. Enable/keep the `postgres-array` feature enabled and ensure sea-orm and sqlx versions are in sync.
  4. If the array may contain mixed/null elements, store it as JSONB or TEXT and parse in application code.

Example fix

// before: DB column is float8[] but entity expects float array
pub samples: Vec<f32>,

// after: match the actual array element type
pub samples: Vec<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("samples").fetch_one(&db).await?;
assert_eq!(row.0, "ARRAY", "expected an array column; confirm element type is float4 with pg_catalog");
// element check:
let elem: (String,) = sqlx::query_as(
    "SELECT format_type(a.atttypid, a.atttypmod) FROM pg_attribute a WHERE a.attrelid = $1::regclass AND a.attname = $2"
).bind("my_table").bind("samples").fetch_one(&db).await?;
assert_eq!(elem.0, "real[]");

Type guard

fn as_f32_array(v: &sea_orm::Value) -> Option<Vec<f32>> {
    match v {
        sea_orm::Value::Array(sea_orm::ArrayType::Float, items) => Some(
            items.iter().filter_map(|x| match x {
                sea_orm::Value::Float(f) => *f,
                _ => None,
            }).collect(),
        ),
        _ => None,
    }
}

Prevention

When it happens

Trigger: Querying a table whose REAL[]/FLOAT4[] column cannot be decoded as Vec<f32>: the column is actually a different array type (FLOAT8[], NUMERIC[]), a partially-typed array, or the `postgres-array` feature decoding hits an element that sqlx rejects.

Common situations: Schema drift after `ALTER COLUMN ... TYPE DOUBLE PRECISION[]`; entity declares `Vec<f32>` but DB holds `float8[]`. Reading arrays through views or foreign tables with remapped types. Postgres domains over array types that sqlx cannot auto-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/0bfa3379831a6be1. Report an issue: GitHub.