{"record":{"id":"c6087dbec007d883","repo":"SeaQL/sea-orm","slug":"failed-to-get-timestamptz-c6087d","errorCode":null,"errorMessage":"Failed to get timestamptz","messagePattern":"Failed to get timestamptz","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":843,"sourceCode":"                            feature = \"postgres-array\"\n                        ))]\n                        \"TIME[]\" => Value::Array(\n                            sea_query::ArrayType::TimeTime,\n                            row.try_get::<Option<Vec<time::Time>>, _>(c.ordinal())\n                                .expect(\"Failed to get time array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::TimeTime(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-chrono\")]\n                        \"TIMESTAMPTZ\" => Value::ChronoDateTimeUtc(\n                            row.try_get::<Option<chrono::DateTime<chrono::Utc>>, _>(c.ordinal())\n                                .expect(\"Failed to get timestamptz\"),\n                        ),\n                        #[cfg(all(feature = \"with-time\", not(feature = \"with-chrono\")))]\n                        \"TIMESTAMPTZ\" => Value::TimeDateTimeWithTimeZone(\n                            row.try_get::<Option<time::OffsetDateTime>, _>(c.ordinal())\n                                .expect(\"Failed to get timestamptz\"),\n                        ),\n\n                        #[cfg(all(feature = \"with-chrono\", feature = \"postgres-array\"))]\n                        \"TIMESTAMPTZ[]\" => Value::Array(\n                            sea_query::ArrayType::ChronoDateTimeUtc,\n                            row.try_get::<Option<Vec<chrono::DateTime<chrono::Utc>>>, _>(\n                                c.ordinal(),\n                            )\n                            .expect(\"Failed to get timestamptz array\")\n                            .map(|vals| {\n                                Box::new(\n                                    vals.into_iter()\n                                        .map(|val| Value::ChronoDateTimeUtc(Some(val)))","sourceCodeStart":825,"sourceCodeEnd":861,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L825-L861","documentation":"This is a panic raised inside sea-orm's ProxyRow conversion when decoding a PostgreSQL TIMESTAMPTZ column. sqlx's `try_get` failed to produce an `Option<chrono::DateTime<Utc>>`, and the code path uses `.expect(...)` instead of returning an error, so the library panics. It almost always means the value in the database cannot be decoded into the expected timestamp-with-timezone type (underlying type mismatch, unrepresentable sentinel value, or a column whose actual type differs from the reported TIMESTAMPTZ).","triggerScenarios":"Querying/fetching a row from PostgreSQL where a column with type name TIMESTAMPTZ cannot be decoded by sqlx into Option<chrono::DateTime<Utc>> — e.g. via `find()`, `from_raw_sql`/`Statement` selects, ProxyRow/into_model decoding, or custom SELECTs whose column metadata says TIMESTAMPTZ but whose value is of another type or encoding.","commonSituations":"Selecting `now()`/`clock_timestamp()` expressions whose metadata mismatches, columns actually declared `timestamp` or custom domain types over timestamptz, reading via raw SQL where aliases change inferred type, storing `infinity`/`-infinity` timestamp sentinels, or sqlx/sea-orm version upgrades changing supported timestamp encodings.","solutions":["Verify the actual PostgreSQL column type with `\\d table` or `SELECT column_name, data_type FROM information_schema.columns` and confirm it is really `timestamp with time zone`; cast in SQL (`col::timestamptz`) if the expression's reported type differs.","Align sea-orm features with your types: enable `with-chrono` and keep the chrono/time feature set consistent across the workspace.","Bump sea-orm and sqlx to matching, current versions — older sqlx versions had known failures decoding certain TIMESTAMPTZ values (e.g. infinity/negative-infinity timestamps or unusual offsets).","If decoding `infinity`/`-infinity` sentinels, replace those values with NULL or concrete timestamps (`UPDATE t SET col = NULL WHERE col = 'infinity'::timestamptz`), since neither chrono nor time can represent them.","As a workaround, select the column as text (`col::text`) and parse it manually in application code instead of relying on ProxyRow's type-based decode."],"exampleFix":"// before (fails: expression reports timestamptz but value is not decodable)\nlet rows = MyEntity::find().from_raw_sql(Statement::from_string(\n    DbBackend::Postgres, \"SELECT now() AS created FROM t\"\n)).into_model::<MyModel>().all(&db).await?;\n\n// after: force an unambiguous, decodable type in SQL\nlet rows = MyEntity::find().from_raw_sql(Statement::from_string(\n    DbBackend::Postgres, \"SELECT now()::timestamptz AS created FROM t\"\n)).into_model::<MyModel>().all(&db).await?;","handlingStrategy":"validation","validationCode":"// Run before decoding: ensure the column really is timestamptz and values are decodable\nlet ok = sqlx::query_scalar::<_, bool>(\n    \"SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name=$1 AND column_name=$2 AND data_type='timestamp with time zone')\"\n).bind(table).bind(column).fetch_one(&db).await?;\nif !ok { return Err(AppError::SchemaMismatch(\"expected timestamptz\")); }\n// additionally scrub sentinels:\n// UPDATE t SET col = NULL WHERE col IN ('infinity'::timestamptz, '-infinity'::timestamptz);","typeGuard":"fn is_timestamptz(meta: &sea_orm::ColumnMeta) -> bool {\n    meta.col_type.as_str().eq_ignore_ascii_case(\"TIMESTAMPTZ\")\n}","tryCatchPattern":"// sea-orm panics here rather than returning Err; isolate the call and convert\nlet result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    entity::Entity::find().from_raw_sql(stmt).into_model::<M>().all(&db)\n}));\nmatch result {\n    Ok(res) => res?,\n    Err(_) => return Err(AppError::DecodeFailed(\"timestamptz column undecodable\")),\n}","preventionTips":["Cast ambiguous expressions to ::timestamptz explicitly in raw SQL.","Prefer `timestamptz` over `timestamp` for all timestamp columns.","Never store `infinity`/`-infinity` sentinel timestamps; use NULL.","Keep sea-orm and sqlx versions in lockstep across the workspace.","Enable the `with-chrono` feature when your models use chrono types."],"tags":["postgres","timestamptz","decode","panic","sqlx"],"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"}