SeaQL/sea-orm · error

Failed to get timetz array

Error message

Failed to get timetz array

What it means

ProxyRow panics with this message when sqlx's `row.try_get::<Option<Vec<chrono::NaiveTime>>, _>` fails while converting a Postgres TIMETZ[] column into Value::Array during row conversion. try_get errors when the column is not actually a timetz array or the inner element decode fails. The expect() turns the sqlx decode error into a panic.

Solutions

  1. Verify the column type is exactly `timetz[]` (not `time[]` or scalar) via information_schema.columns.
  2. Fix the entity field type to match (Vec<NaiveTime> for timetz[] with with-chrono, Vec<time::Time> with with-time) or regenerate entities.
  3. Cast in the query if the source type differs: `SELECT my_arr::timetz[] FROM ...`.
  4. Unwrap nested arrays in SQL (`unnest`) if the value is multi-dimensional.
  5. Check that the postgres-array feature is enabled consistently across sea-orm/sea-query/sqlx.

Example fix

// before: column is `time[]`, entity expects timetz[]
// panic "Failed to get timetz array"

// after: cast at query time
let rows = Task::find().statement(Statement::from_string(
    DbBackend::Postgres,
    "SELECT id, slots::timetz[] AS slots FROM tasks",
)).into_proxy().all(db).await?;
Defensive patterns

Strategy: validation

Validate before calling

let t = sqlx::query(
    "SELECT data_type, udt_name FROM information_schema.columns WHERE table_name=$1 AND column_name=$2"
).bind("shifts").bind("slots")
 .fetch_one(db).await?;
assert_eq!(t.get::<String,_>("data_type"), "ARRAY");
assert_eq!(t.get::<String,_>("udt_name"), "_timetz");

Type guard

fn is_timetz_array(c: &sea_orm::ColumnDef) -> bool {
    matches!(c.get_column_type(), sea_query::ColumnType::Array(_))
}

Try / catch

let decoded = std::panic::catch_unwind(|| {
    // conversion that reads the timetz[] column
});
if decoded.is_err() {
    return Err(DbErr::Custom("timetz[] column decode failed".into()));
}

Prevention

When it happens

Trigger: Selecting a column that is declared/expected as TIMETZ[] but is actually a scalar timetz, a different array type (time[], text[]), or contains elements sqlx cannot decode into chrono::NaiveTime.

Common situations: Array-typed columns mapped with the wrong entity type; postgres-array feature enabled but the column is a one-dimensional vs multi-dimensional array sqlx rejects; migrations changed array element type; custom domains over timetz[].

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/44c7d60d91662c79. Report an issue: GitHub.

Appendix: source

Thrown at src/driver/sqlx_postgres.rs:898

                                    )
                                }),
                        ),

                        #[cfg(feature = "with-chrono")]
                        "TIMETZ" => Value::ChronoTime(
                            row.try_get::<Option<chrono::NaiveTime>, _>(c.ordinal())
                                .expect("Failed to get timetz"),
                        ),
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
                        "TIMETZ" => {
                            Value::TimeTime(row.try_get(c.ordinal()).expect("Failed to get timetz"))
                        }

                        #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
                        "TIMETZ[]" => Value::Array(
                            sea_query::ArrayType::ChronoTime,
                            row.try_get::<Option<Vec<chrono::NaiveTime>>, _>(c.ordinal())
                                .expect("Failed to get timetz array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::ChronoTime(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),
                        #[cfg(all(
                            feature = "with-time",
                            not(feature = "with-chrono"),
                            feature = "postgres-array"
                        ))]
                        "TIMETZ[]" => Value::Array(
                            sea_query::ArrayType::TimeTime,
                            row.try_get::<Option<Vec<time::Time>>, _>(c.ordinal())
                                .expect("Failed to get timetz array")
                                .map(|vals| {

View on GitHub (pinned to e29bcd1b41)