{"record":{"id":"826dc2e7142d05bd","repo":"SeaQL/sea-orm","slug":"failed-to-get-small-integer-826dc2","errorCode":null,"errorMessage":"Failed to get small integer","messagePattern":"Failed to get small integer","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":456,"sourceCode":"                            Value::Bool(row.try_get(c.ordinal()).expect(\"Failed to get boolean\"))\n                        }\n                        #[cfg(feature = \"postgres-array\")]\n                        \"BOOL[]\" => Value::Array(\n                            sea_query::ArrayType::Bool,\n                            row.try_get::<Option<Vec<bool>>, _>(c.ordinal())\n                                .expect(\"Failed to get boolean array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::Bool(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"\\\"CHAR\\\"\" => Value::TinyInt(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get small integer\"),\n                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"\\\"CHAR\\\"[]\" => Value::Array(\n                            sea_query::ArrayType::TinyInt,\n                            row.try_get::<Option<Vec<i8>>, _>(c.ordinal())\n                                .expect(\"Failed to get small integer array\")\n                                .map(|vals: Vec<i8>| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::TinyInt(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"SMALLINT\" | \"SMALLSERIAL\" | \"INT2\" => Value::SmallInt(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get small integer\"),","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L438-L474","documentation":"SeaORM's ProxyRow decodes Postgres columns whose type is \"CHAR\" into Value::TinyInt by calling row.try_get::<i8>(). The .expect() panics when sqlx cannot decode the column's actual value as an i8 — typically because the runtime column type differs from the declared type string (e.g. the column is actually CHAR(n) with multi-byte or longer content, or NULL vs non-NULL expectation mismatch). This is a hard panic, not a recoverable Result.","triggerScenarios":"Calling Entity::find()/raw queries through the proxy driver on Postgres where a column's reported type is \"CHAR\" but the underlying value cannot be decoded as i8 — e.g. a char(n>1) column, a CHAR column holding non-ASCII data, or a NULL returned where the try_get type does not accept it.","commonSituations":"Schema drift after migrations changed column types; using char(n) instead of varchar in Postgres; querying through sea-query-binder's ProxyRow with mismatched type maps between what the migration created and what the code expects.","solutions":["Change the column to varchar/text or a fixed smallint type so the reported type matches the i8 decode path","Alter the query to CAST the column (e.g. CAST(col AS int2)) so sqlx decodes it as the expected type","Update your entity model column_type so the type-string branch taken in ProxyRow matches the real schema","Check the column for NULL values and alter to NOT NULL or COALESCE in the query"],"exampleFix":"// before\n// column: `flag CHAR(3)`\n\n// after\nALTER TABLE my_table ALTER COLUMN flag TYPE varchar(3);\n// or cast in the query\nSELECT CAST(flag AS int2) AS flag FROM my_table;","handlingStrategy":"validation","validationCode":"// Verify column type before querying\nlet rows = sqlx::query(\n    \"SELECT data_type, udt_name FROM information_schema.columns WHERE table_name=$1 AND column_name=$2\"\n).bind(\"my_table\").bind(\"flag\").fetch_all(&db).await?;\nassert_eq!(rows[0].get::<String,_>(\"udt_name\"), \"char\");","typeGuard":"fn is_char_col(udt: &str) -> bool { udt == \"char\" || udt == \"CHAR\" }","tryCatchPattern":"// .expect() panics cannot be caught; avoid the branch instead.\n// Prefer raw sqlx with Result handling:\nlet v: Option<i8> = sqlx::query_scalar(\"SELECT flag FROM my_table\").fetch_one(&db).await?;","preventionTips":["Keep migrations and entity column_type definitions in sync","Prefer varchar/text over char(n) in Postgres schemas","Run a startup schema check comparing information_schema types with entity expectations","Cast ambiguous columns explicitly in queries"],"tags":["postgres","sqlx","type-decode","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"}