{"record":{"id":"ab463d15ca689427","repo":"SeaQL/sea-orm","slug":"failed-to-get-string-array","errorCode":null,"errorMessage":"Failed to get string array","messagePattern":"Failed to get string array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":551,"sourceCode":"                                .expect(\"Failed to get double array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::Double(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"VARCHAR\" | \"CHAR\" | \"TEXT\" | \"NAME\" => Value::String(\n                            row.try_get::<Option<String>, _>(c.ordinal())\n                                .expect(\"Failed to get string\"),\n                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"VARCHAR[]\" | \"CHAR[]\" | \"TEXT[]\" | \"NAME[]\" => Value::Array(\n                            sea_query::ArrayType::String,\n                            row.try_get::<Option<Vec<String>>, _>(c.ordinal())\n                                .expect(\"Failed to get string array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::String(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"BYTEA\" => Value::Bytes(\n                            row.try_get::<Option<Vec<u8>>, _>(c.ordinal())\n                                .expect(\"Failed to get bytes\"),\n                        ),\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\")","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L533-L569","documentation":"This panic comes from `.expect(\"Failed to get string array\")` in `ProxyRow`, decoding a Postgres VARCHAR[]/CHAR[]/TEXT[]/NAME[] column as `Option<Vec<String>>` (behind `postgres-array`). It fires when sqlx cannot decode the array into `Vec<String>` -- the array's element type OID is not text-family (e.g. int[] or bytea[]) or an element contains bytes that are not valid UTF-8. The `expect` escalates this to a panic that aborts the query.","triggerScenarios":"Querying a string-array column that sqlx cannot decode: element type changed after ALTER (e.g. to int[] or bytea[]), data loaded into text[] with non-UTF-8 bytes, or a view/cast changes the array type before it reaches the driver.","commonSituations":"Schema drift: entity declares `Vec<String>` but DB column is a different array type. COPY/import of raw bytes into text[] columns on a SQL_ASCII database. FDW/foreign tables with remapped array types. sqlx/sea-orm version skew affecting array decode.","solutions":["Verify the actual column type (`\\d table`); the entity field must be Vec<String> for text-family arrays -- ALTER the column or change the field type to match.","Cast in the query to force the element type: `SELECT col::TEXT[] AS col`.","Fix the data: re-import non-UTF-8 array elements with proper encoding conversion, or switch the column to bytea[]/JSONB if the data is binary.","Keep sea-orm/sqlx versions in sync and the `postgres-array` feature enabled."],"exampleFix":"// before: entity expects text[] but the column was altered to bytea[]\npub tags: Vec<String>,\n\n// after: match the real element type\npub tags: Vec<Vec<u8>>,","handlingStrategy":"validation","validationCode":"let elem: (String,) = sqlx::query_as(\n    \"SELECT format_type(a.atttypid, a.atttypmod) FROM pg_attribute a WHERE a.attrelid = $1::regclass AND a.attname = $2\"\n).bind(\"my_table\").bind(\"tags\").fetch_one(&db).await?;\nassert!(elem.0.ends_with(\"[]\") && [\"text[]\", \"character varying[]\", \"character[]\", \"name[]\"].contains(&elem.0.as_str()), \"expected a text-family array, got {}\", elem.0);","typeGuard":"fn as_string_array(v: &sea_orm::Value) -> Option<Vec<String>> {\n    match v {\n        sea_orm::Value::Array(sea_orm::ArrayType::String, items) => Some(\n            items.iter().filter_map(|x| match x {\n                sea_orm::Value::String(s) => s.clone(),\n                _ => None,\n            }).collect(),\n        ),\n        _ => None,\n    }\n}","tryCatchPattern":null,"preventionTips":["Pair Vec<String> fields only with text-family array columns; never import raw bytes into text[].","Ensure server encoding is UTF8 before loading array data with COPY.","Enable the `postgres-array` feature and keep sqlx/sea-orm versions in sync.","Cast (::TEXT[]) in raw queries when array element types are uncertain."],"tags":["postgres","sqlx","array","type-mismatch","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"}