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 (src/driver/sqlx_postgres.rs:564). For VARCHAR[]/CHAR[]/TEXT[]/NAME[] columns (with the `postgres-array` feature), the driver decodes `Option<Vec<String>>` and panics when sqlx cannot produce that type. The most common cause is the array's element type not actually being text, or array support not being compiled in.

Source

Thrown at src/driver/sqlx_postgres.rs:564

                                .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. Enable the `postgres-array` feature on sea-orm and sqlx and rebuild.
  2. Check the element type (`SELECT array_typeof(col)`) and cast in SQL: `col::text[]`.
  3. Pin matching sea-orm/sqlx versions; array decoding differs across sqlx releases.
  4. Log with RUST_LOG=sqlx=debug to expose the underlying decode error before the panic.
  5. Swap expect for an error mapped to DbErr::Custom that includes the column ordinal.

Example fix

// before
row.try_get::<Option<Vec<String>>, _>(c.ordinal()).expect("Failed to get string array")
// after
row.try_get::<Option<Vec<String>>, _>(c.ordinal())
    .map_err(|e| DbErr::Custom(format!("text[] decode failed col {}: {e}", c.ordinal())))?
Defensive patterns

Strategy: validation

Validate before calling

// Verify the array holds text elements:
// SELECT array_typeof(col) FROM t LIMIT 1;  -- expect 'text'
// Or cast: SELECT col::text[] FROM ...

Type guard

fn is_text_array_col(c: &ProxyColumn) -> bool {
    matches!(c.ty.as_str(), "VARCHAR[]" | "CHAR[]" | "TEXT[]" | "NAME[]")
}

Try / catch

std::panic::catch_unwind(|| read_row(row))
    .map_err(|p| DbErr::Custom(format!("text[] decode panic: {p:?}")))?;

Prevention

When it happens

Trigger: Reading a text[] column that was created from a non-text array (e.g. int[] or bytea[] under a text[] alias), expressions like array_agg over non-text columns, or a value that is NULL-typed array in a driver version that rejects it for Vec<String>.

Common situations: Forgot `postgres-array` feature flag, ORM/sqlx version skew after an upgrade, schema drift where a column changed to text[] but rows were written with a different element type, or extensions (hstore-like) reporting array type names.

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/00983a71b5ab58be. Report an issue: GitHub.