{"record":{"id":"542cfbadbcabee52","repo":"SeaQL/sea-orm","slug":"failed-to-get-integer-array","errorCode":null,"errorMessage":"Failed to get integer array","messagePattern":"Failed to get integer array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":484,"sourceCode":"                            row.try_get::<Option<Vec<i16>>, _>(c.ordinal())\n                                .expect(\"Failed to get small integer array\")\n                                .map(|vals: Vec<i16>| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::SmallInt(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"INT\" | \"SERIAL\" | \"INT4\" => {\n                            Value::Int(row.try_get(c.ordinal()).expect(\"Failed to get integer\"))\n                        }\n                        #[cfg(feature = \"postgres-array\")]\n                        \"INT[]\" | \"SERIAL[]\" | \"INT4[]\" => Value::Array(\n                            sea_query::ArrayType::Int,\n                            row.try_get::<Option<Vec<i32>>, _>(c.ordinal())\n                                .expect(\"Failed to get integer array\")\n                                .map(|vals: Vec<i32>| {\n                                    Box::new(\n                                        vals.into_iter().map(|val| Value::Int(Some(val))).collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"BIGINT\" | \"BIGSERIAL\" | \"INT8\" => Value::BigInt(\n                            row.try_get(c.ordinal()).expect(\"Failed to get big integer\"),\n                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"BIGINT[]\" | \"BIGSERIAL[]\" | \"INT8[]\" => Value::Array(\n                            sea_query::ArrayType::BigInt,\n                            row.try_get::<Option<Vec<i64>>, _>(c.ordinal())\n                                .expect(\"Failed to get big integer array\")\n                                .map(|vals: Vec<i64>| {\n                                    Box::new(\n                                        vals.into_iter()","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L466-L502","documentation":"Panic while decoding a Postgres integer array column (INT[]/SERIAL[]/INT4[]) in ProxyRow conversion: `row.try_get::<Option<Vec<i32>>, _>(ordinal).expect(\"Failed to get integer array\")`. A NULL array is handled by the Option target, so the failure means an element could not be decoded as i32 — classically NULL elements inside the array (requiring `Vec<Option<i32>>`) — or the runtime data is not an i32 array despite the reported type name.","triggerScenarios":"Selecting an int4 array with NULL elements (e.g. `array_agg(nullable_col)`); array-of-DOMAIN over integer; a view/custom type reporting INT[] whose elements aren't i32-decodable; truncated numeric text stored where the type name lies.","commonSituations":"Aggregating nullable FK/id columns into arrays; unnest/merge patterns producing sparse arrays; schema migration changed element type while type-info still reports INT[]; Postgres DOMAIN arrays.","solutions":["Decode elements as Option: `row.try_get::<Option<Vec<Option<i32>>>, _>(c.ordinal())` and map None elements explicitly.","Remove NULL elements in SQL: `array_remove(col, NULL::int)` or `COALESCE(array_agg(x), ARRAY[]::int[])`.","Cast to plain int[] (`col::int[]`) to bypass DOMAIN arrays.","Verify element type with `pg_typeof` and fix schema or query accordingly.","Enforce NOT NULL on the underlying column when the model expects plain i32 elements."],"exampleFix":"// before (panics on NULL elements)\n\"INT[]\" | \"SERIAL[]\" | \"INT4[]\" => Value::Array(ArrayType::Int,\n    row.try_get::<Option<Vec<i32>>, _>(c.ordinal()).expect(\"Failed to get integer array\")...),\n// after (SQL-side guard)\n// SELECT array_remove(col, NULL::int) AS col FROM t;\n\"INT[]\" | \"SERIAL[]\" | \"INT4[]\" => Value::Array(ArrayType::Int,\n    row.try_get::<Option<Vec<i32>>, _>(c.ordinal()).expect(\"Failed to get integer array\")...),","handlingStrategy":"try-catch","validationCode":"// SELECT bool_and(e IS NOT NULL) FROM unnest(col::int[]) AS e;\n// or in SQL: SELECT array_remove(col, NULL::int) AS col FROM t;","typeGuard":"fn as_i32_array(row: &ProxyRow, col: &str) -> Option<Vec<i32>> {\n    match row.value(col) {\n        Some(Value::Array(ArrayType::Int, vals)) => Some(\n            vals.iter().filter_map(|v| match v {\n                Value::Int(Some(x)) => Some(*x),\n                _ => None,\n            }).collect(),\n        ),\n        _ => None,\n    }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(|| proxy_row_get_i32_array(&row, \"ids\"));\nmatch result {\n    Ok(v) => v,\n    Err(_) => Vec::new(), // or re-query with array_remove(col, NULL::int)\n}","preventionTips":["array_remove(col, NULL) before reading int[] columns built from nullable sources.","COALESCE(array_agg(x), ARRAY[]::int[]) on aggregations.","Decode element-nullable arrays as Vec<Option<i32>> in custom paths.","Confirm element types with pg_typeof after any schema migration."],"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"}