{"record":{"id":"d2f7d8eca02aa736","repo":"SeaQL/sea-orm","slug":"failed-to-get-timestamp-array","errorCode":null,"errorMessage":"Failed to get timestamp array","messagePattern":"Failed to get timestamp array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":716,"sourceCode":"                                }),\n                        ),\n\n                        #[cfg(feature = \"with-chrono\")]\n                        \"TIMESTAMP\" => Value::ChronoDateTime(\n                            row.try_get::<Option<chrono::NaiveDateTime>, _>(c.ordinal())\n                                .expect(\"Failed to get timestamp\"),\n                        ),\n                        #[cfg(all(feature = \"with-time\", not(feature = \"with-chrono\")))]\n                        \"TIMESTAMP\" => Value::TimeDateTime(\n                            row.try_get::<Option<time::PrimitiveDateTime>, _>(c.ordinal())\n                                .expect(\"Failed to get timestamp\"),\n                        ),\n\n                        #[cfg(all(feature = \"with-chrono\", feature = \"postgres-array\"))]\n                        \"TIMESTAMP[]\" => Value::Array(\n                            sea_query::ArrayType::ChronoDateTime,\n                            row.try_get::<Option<Vec<chrono::NaiveDateTime>>, _>(c.ordinal())\n                                .expect(\"Failed to get timestamp array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::ChronoDateTime(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n                        #[cfg(all(\n                            feature = \"with-time\",\n                            not(feature = \"with-chrono\"),\n                            feature = \"postgres-array\"\n                        ))]\n                        \"TIMESTAMP[]\" => Value::Array(\n                            sea_query::ArrayType::TimeDateTime,\n                            row.try_get::<Option<Vec<time::PrimitiveDateTime>>, _>(c.ordinal())\n                                .expect(\"Failed to get timestamp array\")\n                                .map(|vals| {","sourceCodeStart":698,"sourceCodeEnd":734,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L698-L734","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the column/expression type is `timestamp[]` (not `timestamptz[]`); cast in SQL: `SELECT col::timestamp[]`.","For array_agg results, cast: `array_agg(col::timestamp)::timestamp[]`.","Enable and align the `postgres-array` feature across sea-orm-sync and sqlx with a matching chrono version.","Handle NULL elements by using a nullable element type or filtering NULLs in SQL before decoding."],"exampleFix":"// before\nSELECT array_agg(created_at) FROM logs; -- created_at is TIMESTAMPTZ -> panic\n// after\nSELECT array_agg(created_at)::timestamp[] AS created_at FROM logs;","handlingStrategy":"validation","validationCode":"SELECT e.data_type AS element_type FROM information_schema.element_types e\nWHERE e.table_name = $1 AND e.column_name = $2;\n-- element_type must be 'timestamp without time zone' for Vec<NaiveDateTime>","typeGuard":"fn is_timestamp_array(data_type: &str) -> bool { data_type == \"ARRAY\" || data_type == \"timestamp without time zone[]\" }","tryCatchPattern":"let vals = row.try_get::<Option<Vec<chrono::NaiveDateTime>>, _>(idx)\n    .map_err(|e| DecodeError::TimestampArray { column: idx, source: e })?;","preventionTips":["Cast aggregates: array_agg(col::timestamp)::timestamp[]","Check element_types, not just column data_type, for arrays","Enable postgres-array features consistently on all crates","Filter or COALESCE NULL elements before decoding"],"tags":["postgres","sqlx","array-decode","timestamp-array","panic"],"backgroundTag":"type-mismatch","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}