Skip to content

Commit

Permalink
Fix large table count query (#2142)
Browse files Browse the repository at this point in the history
# Description
The current query returns a value in an unexpected format.

# Changes
Cast the returned value to a type that can be converted to `i64`.

## How to test
Ran the modified query in `pgadmin` to check that the type returned from
it is the same as is returned from the regular `count(*)` query.
  • Loading branch information
MartinquaXD authored Dec 7, 2023
1 parent 2f8b38e commit b146193
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/autopilot/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async fn count_rows_in_table(ex: &mut PgConnection, table: &str) -> sqlx::Result
}

async fn estimate_rows_in_table(ex: &mut PgConnection, table: &str) -> sqlx::Result<i64> {
let query = format!("SELECT reltuples FROM pg_class WHERE relname='{table}';");
let query = format!("SELECT reltuples::bigint FROM pg_class WHERE relname='{table}';");
sqlx::query_scalar(&query).fetch_one(ex).await
}

Expand Down

0 comments on commit b146193

Please sign in to comment.