SeaQL/sea-orm · error

Failed to get string array

Error message

Failed to get string array

What it means

This panic comes from `.expect("Failed to get string array")` in `ProxyRow`, decoding a Postgres VARCHAR[]/CHAR[]/TEXT[]/NAME[] column as `Option<Vec<String>>` (behind `postgres-array`). It fires when sqlx cannot decode the array into `Vec<String>` -- the array's element type OID is not text-family (e.g. int[] or bytea[]) or an element contains bytes that are not valid UTF-8. The `expect` escalates this to a panic that aborts the query.

Source

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

                                .expect("Failed to get double array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::Double(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "VARCHAR" | "CHAR" | "TEXT" | "NAME" => Value::String(
                            row.try_get::<Option<String>, _>(c.ordinal())
                                .expect("Failed to get string"),
                        ),
                        #[cfg(feature = "postgres-array")]
                        "VARCHAR[]" | "CHAR[]" | "TEXT[]" | "NAME[]" => Value::Array(
                            sea_query::ArrayType::String,
                            row.try_get::<Option<Vec<String>>, _>(c.ordinal())
                                .expect("Failed to get string array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::String(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "BYTEA" => Value::Bytes(
                            row.try_get::<Option<Vec<u8>>, _>(c.ordinal())
                                .expect("Failed to get bytes"),
                        ),
                        #[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")

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Verify the actual column type (`\d table`); the entity field must be Vec<String> for text-family arrays -- ALTER the column or change the field type to match.
  2. Cast in the query to force the element type: `SELECT col::TEXT[] AS col`.
  3. Fix the data: re-import non-UTF-8 array elements with proper encoding conversion, or switch the column to bytea[]/JSONB if the data is binary.
  4. Keep sea-orm/sqlx versions in sync and the `postgres-array` feature enabled.

Example fix

// before: entity expects text[] but the column was altered to bytea[]
pub tags: Vec<String>,

// after: match the real element type
pub tags: Vec<Vec<u8>>,
Defensive patterns

Strategy: validation

Validate before calling

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("tags").fetch_one(&db).await?;
assert!(elem.0.ends_with("[]") && ["text[]", "character varying[]", "character[]", "name[]"].contains(&elem.0.as_str()), "expected a text-family array, got {}", elem.0);

Type guard

fn as_string_array(v: &sea_orm::Value) -> Option<Vec<String>> {
    match v {
        sea_orm::Value::Array(sea_orm::ArrayType::String, items) => Some(
            items.iter().filter_map(|x| match x {
                sea_orm::Value::String(s) => s.clone(),
                _ => None,
            }).collect(),
        ),
        _ => None,
    }
}

Prevention

When it happens

Trigger: Querying a string-array column that sqlx cannot decode: element type changed after ALTER (e.g. to int[] or bytea[]), data loaded into text[] with non-UTF-8 bytes, or a view/cast changes the array type before it reaches the driver.

Common situations: Schema drift: entity declares `Vec<String>` but DB column is a different array type. COPY/import of raw bytes into text[] columns on a SQL_ASCII database. FDW/foreign tables with remapped array types. sqlx/sea-orm version skew affecting 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/ab463d15ca689427. Report an issue: GitHub.