{"record":{"id":"0536bc78bb47550a","repo":"SeaQL/sea-orm","slug":"failed-to-get-timetz-0536bc","errorCode":null,"errorMessage":"Failed to get timetz","messagePattern":"Failed to get timetz","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":887,"sourceCode":"                            feature = \"postgres-array\"\n                        ))]\n                        \"TIMESTAMPTZ[]\" => Value::Array(\n                            sea_query::ArrayType::TimeDateTimeWithTimeZone,\n                            row.try_get::<Option<Vec<time::OffsetDateTime>>, _>(c.ordinal())\n                                .expect(\"Failed to get timestamptz array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::TimeDateTimeWithTimeZone(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-chrono\")]\n                        \"TIMETZ\" => Value::ChronoTime(\n                            row.try_get::<Option<chrono::NaiveTime>, _>(c.ordinal())\n                                .expect(\"Failed to get timetz\"),\n                        ),\n                        #[cfg(all(feature = \"with-time\", not(feature = \"with-chrono\")))]\n                        \"TIMETZ\" => {\n                            Value::TimeTime(row.try_get(c.ordinal()).expect(\"Failed to get timetz\"))\n                        }\n\n                        #[cfg(all(feature = \"with-chrono\", feature = \"postgres-array\"))]\n                        \"TIMETZ[]\" => Value::Array(\n                            sea_query::ArrayType::ChronoTime,\n                            row.try_get::<Option<Vec<chrono::NaiveTime>>, _>(c.ordinal())\n                                .expect(\"Failed to get timetz array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::ChronoTime(Some(val)))\n                                            .collect(),\n                                    )\n                                }),","sourceCodeStart":869,"sourceCodeEnd":905,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L869-L905","documentation":"ProxyRow panics while decoding a PostgreSQL TIMETZ (time with time zone) column: sqlx's `try_get` into `Option<chrono::NaiveTime>` (chrono path) or time::Time (with-time path) failed and `.expect` converts it to a panic. This means the column value cannot be represented in the expected time type — TIMETZ stores an offset-aware time and not all values decode cleanly, especially with unusual offsets or when the underlying column is not really timetz.","triggerScenarios":"Fetching a TIMETZ column whose value cannot decode into NaiveTime/Time — columns actually declared time/timestamp/interval, domain types over timetz, raw-SQL expressions with mismatched metadata, or values with large UTC offsets that cannot round-trip into the target type.","commonSituations":"Legacy schemas where an `interval` column is labeled timetz in metadata; `timetz` values with offsets like `+13:59` that chrono/time reject on decode; raw selects casting `now()::timetz` through views; feature-flag mismatches so the wrong decode arm runs.","solutions":["Confirm the true column type (`\\d table`); if it is `time without time zone` or `interval`, cast in SQL to `col::timetz` or fix the schema.","Normalize offsets: return `col AT TIME ZONE 'UTC'` so decode targets a well-behaved value, or change the column to `timestamptz` if the offset actually matters.","Align feature flags (`with-chrono` vs `with-time`) so the matching decode arm handles your data.","Update sea-orm/sqlx for decode fixes for edge-case timetz offsets.","Workaround: select `col::text` and parse the time manually."],"exampleFix":"// before: column is interval mislabeled as timetz in a view\n\"SELECT duration AS started FROM jobs\"\n\n// after\n\"SELECT (started)::timetz AS started FROM jobs\"  // or fix the view to use timetz","handlingStrategy":"validation","validationCode":"let dtype = sqlx::query_scalar::<_, String>(\n    \"SELECT data_type FROM information_schema.columns WHERE table_name=$1 AND column_name=$2\"\n).bind(table).bind(column).fetch_one(&db).await?;\nif dtype != \"time with time zone\" { return Err(AppError::SchemaMismatch(format!(\"expected timetz, got {dtype}\"))); }","typeGuard":"fn is_timetz(meta: &sea_orm::ColumnMeta) -> bool {\n    meta.col_type.as_str().eq_ignore_ascii_case(\"TIMETZ\")\n}","tryCatchPattern":"let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    entity::Entity::find().from_raw_sql(stmt).into_model::<M>().all(&db)\n}));\nlet rows = res.map_err(|_| AppError::DecodeFailed(\"timetz decode panicked\"))??;","preventionTips":["Prefer `timestamptz` or `time without time zone` over `timetz` (Postgres docs discourage timetz).","Cast raw-SQL time expressions explicitly (col::timetz or AT TIME ZONE 'UTC').","Check for interval columns mislabeled as timetz in views.","Normalize offsets to UTC before decoding.","Verify feature flags (with-chrono/with-time) match your model types."],"tags":["postgres","timetz","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"}