{"record":{"id":"877e584a40a0c338","repo":"SeaQL/sea-orm","slug":"failed-to-get-small-integer-array","errorCode":null,"errorMessage":"Failed to get small integer array","messagePattern":"Failed to get small integer array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":449,"sourceCode":"                                .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\"),\n                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"SMALLINT[]\" | \"SMALLSERIAL[]\" | \"INT2[]\" => Value::Array(\n                            sea_query::ArrayType::SmallInt,\n                            row.try_get::<Option<Vec<i16>>, _>(c.ordinal())\n                                .expect(\"Failed to get small integer array\")","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L431-L467","documentation":"Panic while decoding a Postgres `\"char\"[]` array column in ProxyRow conversion: `row.try_get::<Option<Vec<i8>>, _>(ordinal).expect(\"Failed to get small integer array\")`. A NULL array is tolerated by the `Option` target, so failure means an element could not be decoded as `i8` — typically NULL elements inside the array (needing `Vec<Option<i8>>`) or the runtime array not actually holding `\"char\"` values despite the reported type name.","triggerScenarios":"Selecting a `\"char\"[]` column that contains NULL elements (e.g. `ARRAY['a'::\"char\", NULL]`); array-of-DOMAIN over `\"char\"`; or a view/custom type reporting \"CHAR[]\" whose data is not a smallint-decodable array.","commonSituations":"Aggregating catalog `\"char\"` columns with ARRAY_AGG over rows that include NULLs; migrating queries against system catalogs where `\"char\"` flags are nullable; custom aggregate expressions producing sparse arrays.","solutions":["Decode elements as Option: `row.try_get::<Option<Vec<Option<i8>>>, _>(c.ordinal())` and map None elements appropriately.","Remove NULL elements in SQL: `array_remove(col, NULL::\"char\")` or wrap aggregation with `COALESCE(array_agg(col), ARRAY[]::\"char\"[])`.","Cast in the query to a plain `\"char\"[]` if a domain/array-of-domain is in play.","Verify element type via `pg_typeof` and fix the schema or the query cast.","Constrain the source data so elements are always non-null when the model expects i8."],"exampleFix":"// before (panics on NULL elements)\n\"\\\"CHAR\\\"[]\" => Value::Array(ArrayType::TinyInt,\n    row.try_get::<Option<Vec<i8>>, _>(c.ordinal()).expect(\"Failed to get small integer array\")...),\n// after (SQL-side guard)\n// SELECT array_remove(col, NULL::\"char\") AS col FROM t;\n\"\\\"CHAR\\\"[]\" => Value::Array(ArrayType::TinyInt,\n    row.try_get::<Option<Vec<i8>>, _>(c.ordinal()).expect(\"Failed to get small integer array\")...),","handlingStrategy":"try-catch","validationCode":"// SELECT bool_and(e IS NOT NULL) FROM unnest(col::\"char\"[]) AS e;\n// or in SQL: SELECT array_remove(col, NULL::\"char\") AS col FROM t;","typeGuard":"fn as_char_array(row: &ProxyRow, col: &str) -> Option<Vec<i8>> {\n    match row.value(col) {\n        Some(Value::Array(ArrayType::TinyInt, vals)) => Some(\n            vals.iter().filter_map(|v| match v {\n                Value::TinyInt(Some(x)) => Some(*x),\n                _ => None,\n            }).collect(),\n        ),\n        _ => None,\n    }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(|| proxy_row_get_i8_array(&row, \"flags\"));\nmatch result {\n    Ok(v) => v,\n    Err(_) => Vec::new(), // or re-query with array_remove(col, NULL::\"char\")\n}","preventionTips":["Strip NULL elements with array_remove before reading \"char\"[] columns.","Aggregate with COALESCE(array_agg(x), ARRAY[]::\"char\"[]) to avoid NULL-laden results.","Decode element-nullable arrays as Vec<Option<i8>> in custom paths.","Verify element types with pg_typeof/unnest before binding fixed decode targets."],"tags":["postgres","sqlx","array-decode","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"}