SeaQL/sea-orm · error

Failed to get timetz array

Error message

Failed to get timetz array

What it means

For `TIMETZ[]` columns under `with-chrono` + `postgres-array`, ProxyRow decodes `try_get::<Option<Vec<chrono::NaiveTime>>>`; a decode Err makes `.expect("Failed to get timetz array")` panic. The array element type or encoding was not decodable as chrono NaiveTime.

Source

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

                                    )
                                }),
                        ),

                        #[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)

Solutions

  1. Check udt_name equals `timetz[]`; if it is `time[]` or other, align schema or query mapping.
  2. Migrate elements from timetz to plain time to match the NaiveTime mapping: rebuild the array with `AT TIME ZONE 'UTC'`.
  3. Enable `with-chrono` + `postgres-array` on sea-orm-sync and matching sqlx `chrono` feature.
  4. Cast to text[] in SQL and parse manually if the offsets must be retained.

Example fix

// before: column is time[] but entity expects TIMETZ[] handling

// after
// ALTER TABLE t ALTER COLUMN c TYPE timetz[] USING c::timetz[];
// -- or better, move to plain time[] and let chrono NaiveTime decode directly
Defensive patterns

Strategy: validation

Validate before calling

let ty: (String,) = sqlx::query_as(
    "SELECT udt_name FROM information_schema.columns WHERE table_name = $1 AND column_name = $2",
).bind("t").bind("c").fetch_one(db).await?;
assert_eq!(ty.0, "_timetz", "c must be timetz[] to decode as Vec<chrono::NaiveTime>");

Type guard

fn is_timetz_array(udt_name: &str) -> bool { udt_name == "_timetz" }

Try / catch

let vals = row.try_get::<Option<Vec<chrono::NaiveTime>>, _>(idx)
    .map_err(|e| DecodeError::TimetzArray(e.to_string()))?;

Prevention

When it happens

Trigger: Selecting a timetz[] column when the element OID is actually `time[]`, `timestamp[]`, or text[]; or when sqlx's chrono array decoder for timetz elements is not available at the compiled versions.

Common situations: Array columns of legacy `time with time zone` values; migrations that changed element type; feature/dependency version skew between sea-orm, sea-query, and sqlx.

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/6825c8495eb1513a. Report an issue: GitHub.