SeaQL/sea-orm · error
Failed to get oid
Error message
Failed to get oid
What it means
This panic fires when sea-orm's Postgres decoder cannot read an OID-typed column into i64 via `row.try_get`. OIDs in Postgres are unsigned 32-bit values; sea-orm maps them to BigInt. try_get fails if the actual cell is not the expected type (e.g. the query returns text or a regclass rendering), the type OID isn't recognized, or NULL arrives where sqlx's decode path cannot produce the requested Option type. The `.expect` converts the error into a panic.
Source
Thrown at sea-orm-sync/src/driver/sqlx_postgres.rs:624
feature = "with-rust_decimal",
not(feature = "with-bigdecimal"),
feature = "postgres-array"
))]
"NUMERIC[]" => Value::Array(
sea_query::ArrayType::Decimal,
row.try_get::<Option<Vec<rust_decimal::Decimal>>, _>(c.ordinal())
.expect("Failed to get numeric array")
.map(|vals| {
Box::new(
vals.into_iter()
.map(|val| Value::Decimal(Some(val)))
.collect(),
)
}),
),
"OID" => {
Value::BigInt(row.try_get(c.ordinal()).expect("Failed to get oid"))
}
#[cfg(feature = "postgres-array")]
"OID[]" => Value::Array(
sea_query::ArrayType::BigInt,
row.try_get::<Option<Vec<i64>>, _>(c.ordinal())
.expect("Failed to get oid array")
.map(|vals| {
Box::new(
vals.into_iter()
.map(|val| Value::BigInt(Some(val)))
.collect(),
)
}),
),
#[cfg(feature = "with-json")]
"JSON" | "JSONB" => Value::Json(
row.try_get::<Option<serde_json::Value>, _>(c.ordinal())View on GitHub (pinned to e29bcd1b41)
Solutions
- Inspect the returned type (`SELECT pg_typeof(oid_col)`) and remove SQL casts such as `::regclass` or `::text` on oid columns.
- Match your entity/`ColumnDef` type name to the real column type (declare it as integer if the column is int4, not oid).
- Keep sea-orm and sqlx versions in sync; a mismatched sqlx version can change OID decoding.
- Cast explicitly in SQL to the type you intend: `SELECT oid::bigint FROM pg_class`.
Example fix
// before SELECT oid::regclass FROM pg_class WHERE relname = 'users'; // after SELECT oid FROM pg_class WHERE relname = 'users';
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the returned type before decoding as oid:
let t = db.query_one(Statement::from_string(
DatabaseBackend::Postgres,
"SELECT pg_typeof(oid)::text FROM pg_class LIMIT 1",
)).await?;
// expect "oid"; if it says "text" or "regclass", remove casts in your query. Try / catch
// Decode defensively via raw SQL as text first, then parse:
let raw = db.query_all(Statement::from_string(
DatabaseBackend::Postgres,
"SELECT oid::text FROM pg_class",
)).await?;
let oids: Vec<i64> = raw.iter().filter_map(|r| r.try_get::<String, _>(0).ok()?.parse().ok()).collect(); Prevention
- Never cast oid columns to regclass/text in queries fetched through entities.
- Check `pg_typeof` output when writing raw catalog queries.
- Match your ColumnDef type name to the actual storage type.
- Pin sqlx to the version sea-orm was tested against.
When it happens
Trigger: Selecting an OID column (e.g. from pg_catalog tables like pg_class.oid, pg_type.oid, or a custom `oid` column) through a raw query or entity whose column type string resolves to "OID", while sqlx returns a different internal type; casting oid to regclass/text in SQL (`oid::regclass`) changes the returned type and breaks the decoder.
Common situations: Introspection queries against Postgres system catalogs; raw SQL where `oid` was cast to text or regclass for readability; schema drift where a column named like an oid is actually integer/text.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Failed to get numeric array
- Failed to get oid array
- Failed to get json
- Failed to get json array
- Failed to get ip address
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/69e115258f5c2f17.
Report an issue: GitHub.