aggregate data fix

This commit is contained in:
Mateusz Gruszczyński
2026-07-28 12:05:47 +02:00
parent dacb754226
commit 762638a681
3 changed files with 7 additions and 5 deletions
+5 -3
View File
@@ -181,11 +181,13 @@ pub async fn list_note_stats(
DatabaseKind::Postgres => "$1",
DatabaseKind::Sqlite | DatabaseKind::MySql => "?",
};
// PostgreSQL promotes SUM(BIGINT) to NUMERIC. sqlx::Any cannot decode the
// database-specific NUMERIC type, so normalize the aggregate to BIGINT.
// PostgreSQL and MySQL promote SUM(BIGINT) to database-specific decimal
// types. sqlx::Any cannot decode those types, so normalize the aggregate
// to a signed 64-bit integer before reading it.
let file_size_sum = match pool.kind() {
DatabaseKind::Postgres => "COALESCE(SUM(f.size_bytes), 0)::BIGINT",
DatabaseKind::Sqlite | DatabaseKind::MySql => "COALESCE(SUM(f.size_bytes), 0)",
DatabaseKind::MySql => "CAST(COALESCE(SUM(f.size_bytes), 0) AS SIGNED)",
DatabaseKind::Sqlite => "COALESCE(SUM(f.size_bytes), 0)",
};
let query = format!(
"SELECT n.id AS note_id, \