SeaQL/sea-orm · error

Failed to get unsigned big integer

Error message

Failed to get unsigned big integer

What it means

In `ProxyRow`'s MySQL decoding, columns with metadata `MEDIUMINT UNSIGNED` or `BIGINT UNSIGNED` are fetched with `row.try_get::<u64>` and unwrapped with `.expect("Failed to get unsigned big integer")`. If sqlx cannot decode the value as an unsigned 64-bit integer (NULL, incompatible underlying type, schema drift), the expect panics. It means the row value does not match the declared unsigned wide-integer column type.

Source

Thrown at src/driver/sqlx_mysql.rs:413

                    match c.type_info().name() {
                        "TINYINT(1)" | "BOOLEAN" => {
                            Value::Bool(row.try_get(c.ordinal()).expect("Failed to get boolean"))
                        }
                        "TINYINT UNSIGNED" => Value::TinyUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned tiny integer"),
                        ),
                        "SMALLINT UNSIGNED" => Value::SmallUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned small integer"),
                        ),
                        "INT UNSIGNED" => Value::Unsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned integer"),
                        ),
                        "MEDIUMINT UNSIGNED" | "BIGINT UNSIGNED" => Value::BigUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned big integer"),
                        ),
                        "TINYINT" => Value::TinyInt(
                            row.try_get(c.ordinal())
                                .expect("Failed to get tiny integer"),
                        ),
                        "SMALLINT" => Value::SmallInt(
                            row.try_get(c.ordinal())
                                .expect("Failed to get small integer"),
                        ),
                        "INT" => {
                            Value::Int(row.try_get(c.ordinal()).expect("Failed to get integer"))
                        }
                        "MEDIUMINT" | "BIGINT" => Value::BigInt(
                            row.try_get(c.ordinal()).expect("Failed to get big integer"),
                        ),
                        "FLOAT" => {
                            Value::Float(row.try_get(c.ordinal()).expect("Failed to get float"))
                        }

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Ensure the column is NOT NULL or change the entity field to `Option<u64>` so NULL decodes cleanly
  2. Regenerate entities from the current schema to eliminate type drift
  3. In proxy/mock tests, return values typed exactly as `u64` for BIGINT UNSIGNED columns
  4. Check the raw SQL's SELECT list for expressions (e.g. COALESCE, CAST) that change the column's type/nullability

Example fix

// before
let v: u64 = row.try_get(c.ordinal()).expect("Failed to get unsigned big integer");
// after (library-side hardening)
let v: u64 = row.try_get::<Option<u64>, _>(c.ordinal())?.unwrap_or_default();
Defensive patterns

Strategy: validation

Validate before calling

// Check BIGINT UNSIGNED columns are NOT NULL before decoding
SELECT IS_NULLABLE, COLUMN_TYPE FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?;
// expect COLUMN_TYPE = 'bigint unsigned', IS_NULLABLE = 'NO'

Type guard

fn is_u64_compatible(col_type: &str, nullable: bool, value_is_null: bool) -> bool {
    matches!(col_type.to_ascii_lowercase().as_str(), "bigint unsigned" | "mediumint unsigned")
        && !nullable && !value_is_null
}

Prevention

When it happens

Trigger: A `BIGINT UNSIGNED`/`MEDIUMINT UNSIGNED` column containing NULL, or actual server value of a different type than the described metadata, while decoding rows through the proxy driver.

Common situations: Entity expects non-nullable `BIGINT UNSIGNED` (e.g. auto-increment id) but raw SQL returns NULL for it; mock proxy test data supplies a string or signed value for a declared BIGINT UNSIGNED column; cached prepared-statement metadata predates an ALTER TABLE.

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


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/097a25798d70ee9d. Report an issue: GitHub.