SeaQL/sea-orm · error

Failed to get timestamp array

Error message

Failed to get timestamp array

What it means

This panic fires when decoding a Postgres TIMESTAMP[] array column into Vec<chrono::NaiveDateTime> (with-chrono + postgres-array features). sqlx's try_get fails because the value is not a Postgres array of timestamps compatible with that element type, and the .expect("Failed to get timestamp array") turns it into a panic. Array decoding additionally fails when the element type reported by the server does not match the expected element decoder.

Source

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

                                }),
                        ),

                        #[cfg(feature = "with-chrono")]
                        "TIMESTAMP" => Value::ChronoDateTime(
                            row.try_get::<Option<chrono::NaiveDateTime>, _>(c.ordinal())
                                .expect("Failed to get timestamp"),
                        ),
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
                        "TIMESTAMP" => Value::TimeDateTime(
                            row.try_get::<Option<time::PrimitiveDateTime>, _>(c.ordinal())
                                .expect("Failed to get timestamp"),
                        ),

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

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Confirm the column/expression type is `timestamp[]` (not `timestamptz[]`); cast in SQL: `SELECT col::timestamp[]`.
  2. For array_agg results, cast: `array_agg(col::timestamp)::timestamp[]`.
  3. Enable and align the `postgres-array` feature across sea-orm-sync and sqlx with a matching chrono version.
  4. Handle NULL elements by using a nullable element type or filtering NULLs in SQL before decoding.

Example fix

// before
SELECT array_agg(created_at) FROM logs; -- created_at is TIMESTAMPTZ -> panic
// after
SELECT array_agg(created_at)::timestamp[] AS created_at FROM logs;
Defensive patterns

Strategy: validation

Validate before calling

SELECT e.data_type AS element_type FROM information_schema.element_types e
WHERE e.table_name = $1 AND e.column_name = $2;
-- element_type must be 'timestamp without time zone' for Vec<NaiveDateTime>

Type guard

fn is_timestamp_array(data_type: &str) -> bool { data_type == "ARRAY" || data_type == "timestamp without time zone[]" }

Try / catch

let vals = row.try_get::<Option<Vec<chrono::NaiveDateTime>>, _>(idx)
    .map_err(|e| DecodeError::TimestampArray { column: idx, source: e })?;

Prevention

When it happens

Trigger: Selecting a column typed as "TIMESTAMP[]" whose actual element type is timestamptz, an unmapped custom array (_mytype), or NULL array elements where the decoder path expects decodable values; also when postgres-array support is half-configured.

Common situations: Schema drift changing timestamp[] to timestamptz[]; ORM/DB type-name mismatch after server upgrade; queries with `array_agg(timestamp_col)` whose result element type differs; trying to decode a scalar timestamp into an array arm by mistake.

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