Skip to content

Sqlite mismatched types error #2093

@mrmykey

Description

@mrmykey

sqlx 6.1 fails when running SQLite returning query with a float which ends with 0.
Works with 1.1, fails with 1.0

// CREATE TABLE data_table(id INTEGER PRIMARY KEY AUTOINCREMENT, number REAL);
#[derive(sqlx::FromRow)]
struct DataTable { id: i64, number: f64 }

#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
    let pool = SqlitePool::connect("sqlite:app.db").await?;
    let sql = "insert into data_table (number) values (?) returning id, number";
    let _result = sqlx::query_as::<_, DataTable>(sql).bind(1.0).fetch_one(&pool).await?;
    Ok(())
}

Error: ColumnDecode { index: "\"number\"", source: "mismatched types; Rust type `f64` (as SQL type `REAL`) is not compatible with SQL type `INTEGER`" }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbug:dbInvolves a bug in the database serverdb:sqliteRelated to SQLite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions