sqlx not converting to i64 from bigdecimal
I have a query that fetches the size of a repository in bytes. Let's take an example: the size of that file is 199624061 bytes. When I tried to fetch the size I got this 844433520066560. This is my query:
pub async fn get_repositories(
connection: &mut <Database as sqlx::Database>::Connection,
id: &Uuid,
) -> Result<Vec<(DockerRepository, u64)>, sqlx::Error> {
let rows = query!(
r#"
SELECT
id as "id: Uuid",
size as "size!: i64"
FROM
repository
WHERE
id = $1;
"#,
id as _
)
.fetch_all(&mut *connection)
.await?
.into_iter()
.map(|row| {
(
Repository {
id: row.id,
size,
}
)
})
.collect();
Ok(rows)
}
I solved this by removing the i64 from the query and converted the bigdecimal to u64 using an external crate. But I should ideally be able to convert into i64 thorugh sqlx right?
What database are you using (Postgres/MySQL/MSSQL/SQLite)? I'm guessing SQLite because you're using $1 as a bind parameter but Postgres doesn't support u64.
We actually removed support for u64 from the SQLite driver because we can't support the full range of values: https://github.com/launchbadge/sqlx/commit/2fd26b5504433fbe6873c807521e3d48f7dbc6bb
SQLite might accept UNSIGNED BIG INT for the type of a column but it'll still store it as a signed 64-bit integer.
Actually... how are you even doing this then? We removed that impl between 0.5.0 and 0.5.1 then yanked 0.5.0.
What database are you using (Postgres/MySQL/MSSQL/SQLite)? I'm guessing SQLite because you're using
$1as a bind parameter but Postgres doesn't supportu64.We actually removed support for
u64from the SQLite driver because we can't support the full range of values: https://github.com/launchbadge/sqlx/commit/2fd26b5504433fbe6873c807521e3d48f7dbc6bbSQLite might accept
UNSIGNED BIG INTfor the type of a column but it'll still store it as a signed 64-bit integer.Actually... how are you even doing this then? We removed that impl between 0.5.0 and 0.5.1 then yanked 0.5.0.
Sorry, I meant i64 and not u64. I am using postgres database for this query
And the repository.size column is NUMERIC?
it is bigint
But you mentioned "bigdecimal" a couple of times. Was that a mistake?
in the create table query i make it as bigint. However in that select query when I don't cast it to i64 rust shows me that the data type of size is bigdecimal
this is the create table query
CREATE TABLE repository(
id UUID NOT NULL,
size BIGINT NOT NULL
);
Is this fixed by #3184 ?