From c03e887b71a6239924c23a4d690f766df8ea8488 Mon Sep 17 00:00:00 2001 From: Aleksey Shakhmatov Date: Sat, 23 May 2026 18:17:55 +0300 Subject: [PATCH] fix(chat): decode pg_class.reltuples as f32 in sample_data probe pg_class.reltuples is `real` (FLOAT4). Reading it as f64 via query_scalar made the sample_data tool fail with a sqlx type-mismatch ("f64 (FLOAT8) is not compatible with FLOAT4") before any rows were fetched. Decode as f32 and widen. --- src-tauri/src/commands/chat_tools.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/commands/chat_tools.rs b/src-tauri/src/commands/chat_tools.rs index ad4ff15..35154e1 100644 --- a/src-tauri/src/commands/chat_tools.rs +++ b/src-tauri/src/commands/chat_tools.rs @@ -899,7 +899,9 @@ async fn build_sample_sql_postgres( limit: u32, ) -> TuskResult { let pool = state.get_pool(connection_id).await?; - let reltuples: f64 = sqlx::query_scalar( + // pg_class.reltuples is `real` (FLOAT4); decode as f32 then widen — sqlx is + // strict and reading it directly as f64 fails with a type-mismatch error. + let reltuples: f64 = sqlx::query_scalar::<_, f32>( "SELECT c.reltuples FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid \ WHERE n.nspname = $1 AND c.relname = $2", ) @@ -908,7 +910,7 @@ async fn build_sample_sql_postgres( .fetch_optional(&pool) .await .map_err(TuskError::Database)? - .unwrap_or(0.0); + .unwrap_or(0.0) as f64; let qualified = format!("{}.{}", escape_ident(schema), escape_ident(table)); if reltuples > 0.0 {