SeaQL/sea-orm · error

Failed to get timestamptz array

Error message

Failed to get timestamptz array

What it means

For a `TIMESTAMPTZ[]` column under `with-chrono` + `postgres-array`, ProxyRow decodes with `try_get::<Option<Vec<chrono::DateTime<chrono::Utc>>>>`; a decode Err triggers `.expect("Failed to get timestamptz array")`. The array's element OID or encoding was not decodable as chrono DateTime<Utc> elements.

Source

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

                        #[cfg(feature = "with-chrono")]
                        "TIMESTAMPTZ" => Value::ChronoDateTimeUtc(
                            row.try_get::<Option<chrono::DateTime<chrono::Utc>>, _>(c.ordinal())
                                .expect("Failed to get timestamptz"),
                        ),
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
                        "TIMESTAMPTZ" => Value::TimeDateTimeWithTimeZone(
                            row.try_get::<Option<time::OffsetDateTime>, _>(c.ordinal())
                                .expect("Failed to get timestamptz"),
                        ),

                        #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
                        "TIMESTAMPTZ[]" => Value::Array(
                            sea_query::ArrayType::ChronoDateTimeUtc,
                            row.try_get::<Option<Vec<chrono::DateTime<chrono::Utc>>>, _>(
                                c.ordinal(),
                            )
                            .expect("Failed to get timestamptz array")
                            .map(|vals| {
                                Box::new(
                                    vals.into_iter()
                                        .map(|val| Value::ChronoDateTimeUtc(Some(val)))
                                        .collect(),
                                )
                            }),
                        ),
                        #[cfg(all(
                            feature = "with-time",
                            not(feature = "with-chrono"),
                            feature = "postgres-array"
                        ))]
                        "TIMESTAMPTZ[]" => Value::Array(
                            sea_query::ArrayType::TimeDateTimeWithTimeZone,
                            row.try_get::<Option<Vec<time::OffsetDateTime>>, _>(c.ordinal())
                                .expect("Failed to get timestamptz array")
                                .map(|vals| {

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Inspect udt_name of the column: it must be `timestamptz[]`; if it is `timestamp[]`, alter the column or the query mapping.
  2. Replace 'infinity'/'-infinity' array elements with NULL or finite timestamps.
  3. Enable `with-chrono` and `postgres-array` features and keep sea-orm/sea-query/sqlx versions matched.
  4. Cast to text[] in SQL and parse manually if special values must be preserved.

Example fix

// before
// SELECT run_times FROM batches; -- run_times is timestamp[]

// after
// ALTER TABLE batches ALTER COLUMN run_times TYPE timestamptz[] USING run_times::timestamptz[];
// or: SELECT ARRAY(SELECT x::timestamptz FROM unnest(run_times) x) AS run_times FROM batches;
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("batches").bind("run_times").fetch_one(db).await?;
assert_eq!(ty.0, "_timestamptz", "run_times must be timestamptz[]");

Type guard

fn is_timestamptz_array(udt_name: &str) -> bool { udt_name == "_timestamptz" }

Try / catch

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

Prevention

When it happens

Trigger: Selecting a timestamptz[] column when the column is actually timestamp[] (different element OID), contains 'infinity' elements, or the sqlx array decoder for chrono timestamptz is not compiled/aligned.

Common situations: Array columns added by migrations with element type drift; chrono/time feature mixing; reading dumps where arrays were created as timestamp[] but typed as timestamptz[] in ORM metadata.

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