{"record":{"id":"8a93300d2e29505f","repo":"SeaQL/sea-orm","slug":"failed-to-get-numeric","errorCode":null,"errorMessage":"Failed to get numeric","messagePattern":"Failed to get numeric","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":582,"sourceCode":"                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"BYTEA[]\" => Value::Array(\n                            sea_query::ArrayType::Bytes,\n                            row.try_get::<Option<Vec<Vec<u8>>>, _>(c.ordinal())\n                                .expect(\"Failed to get bytes array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::Bytes(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-bigdecimal\")]\n                        \"NUMERIC\" => Value::BigDecimal(\n                            row.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())\n                                .expect(\"Failed to get numeric\"),\n                        ),\n                        #[cfg(all(\n                            feature = \"with-rust_decimal\",\n                            not(feature = \"with-bigdecimal\")\n                        ))]\n                        \"NUMERIC\" => {\n                            Value::Decimal(row.try_get(c.ordinal()).expect(\"Failed to get numeric\"))\n                        }\n\n                        #[cfg(all(feature = \"with-bigdecimal\", feature = \"postgres-array\"))]\n                        \"NUMERIC[]\" => Value::Array(\n                            sea_query::ArrayType::BigDecimal,\n                            row.try_get::<Option<Vec<bigdecimal::BigDecimal>>, _>(c.ordinal())\n                                .expect(\"Failed to get numeric array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::BigDecimal(Some(val)))","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L564-L600","documentation":"This panic comes from `.expect(\"Failed to get numeric\")` in `ProxyRow`, decoding a Postgres NUMERIC column as `Option<bigdecimal::BigDecimal>` when the `with-bigdecimal` feature is enabled. It fires when sqlx cannot decode the value as BigDecimal -- usually the runtime column type is not actually `numeric` (e.g. it was ALTERed to float8 or text), or the crate's bigdecimal/sqlx versions are incompatible so the decode impl rejects the wire format. The `expect` escalates this to a panic.","triggerScenarios":"Any SeaORM query returning a NUMERIC column that cannot be decoded into BigDecimal: column type altered away from numeric, a domain type over numeric with unexpected OIDs, or a version mismatch between `bigdecimal` and `sqlx` crates after a dependency update.","commonSituations":"`ALTER COLUMN ... TYPE DOUBLE PRECISION` for performance while the model still expects a decimal. Cargo dependency drift: sea-orm pinned to bigdecimal 0.3 while sqlx expects 0.4 (feature mismatch). Reading numeric columns through views that cast to float.","solutions":["Confirm the actual column type is NUMERIC (`\\d table`); ALTER it back or map the entity field to f64/Decimal to match the real type.","Align `bigdecimal` and `sqlx` versions with those required by your sea-orm version (check sea-orm's Cargo.toml for the exact feature-mapped versions).","Cast in the query: `SELECT col::NUMERIC AS col` to guarantee a numeric reaches the driver.","Alternatively switch to `with-rust_decimal` (the fallback branch in this code) and map the field to rust_decimal::Decimal."],"exampleFix":"// before: column altered to float8 but entity still uses BigDecimal\npub rate: BigDecimal,\n\n// after: match the actual column type\npub rate: f64,","handlingStrategy":"validation","validationCode":"let row: (String, ) = sqlx::query_as(\n    \"SELECT data_type FROM information_schema.columns WHERE table_name = $1 AND column_name = $2\"\n).bind(\"my_table\").bind(\"rate\").fetch_one(&db).await?;\nassert_eq!(row.0, \"numeric\", \"rate must be NUMERIC, got {}\", row.0);\n// Also verify bigdecimal version matches sea-orm's requirement in Cargo.toml","typeGuard":"fn as_bigdecimal(v: &sea_orm::Value) -> Option<bigdecimal::BigDecimal> {\n    match v {\n        sea_orm::Value::BigDecimal(d) => d.clone(),\n        _ => None,\n    }\n}","tryCatchPattern":null,"preventionTips":["Pin the `bigdecimal` crate to the exact version your sea-orm release depends on (check its Cargo.toml).","Use BigDecimal only for true NUMERIC columns; f64/Double for float8.","Run ALTER COLUMN ... TYPE changes through migrations that also update entities.","Cast (::NUMERIC) in raw SQL when reading numerics through views."],"tags":["postgres","sqlx","numeric","bigdecimal","type-mismatch"],"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"}