From 8013a19e503434965705a5003ba7d1fdee224b29 Mon Sep 17 00:00:00 2001 From: yavon007 Date: Sun, 3 May 2026 21:03:49 +0800 Subject: [PATCH] fix: separate key columns from included in PG index, add varbinary(max) for SQL Server PostgreSQL list_indexes was returning all_cols (key + included) in IndexInfo.columns, causing DDL and UI duplication. Now only key columns are returned in columns, with included columns correctly split via indnkeyatts. SQL Server varbinary now handles Some(-1) to display varbinary(max). --- src-tauri/src/db/postgres.rs | 3 ++- src-tauri/src/db/sqlserver.rs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/db/postgres.rs b/src-tauri/src/db/postgres.rs index 6dcef76cd6..6c90481de7 100644 --- a/src-tauri/src/db/postgres.rs +++ b/src-tauri/src/db/postgres.rs @@ -305,10 +305,11 @@ pub async fn list_indexes(pool: &PgPool, schema: &str, table: &str) -> Result = row.get::, _>("columns"); let nkeyatts = row.get::, _>("nkeyatts").unwrap_or(all_cols.len() as i16) as usize; + let key_cols = all_cols[..nkeyatts].to_vec(); let included = if nkeyatts < all_cols.len() { all_cols[nkeyatts..].to_vec() } else { vec![] }; IndexInfo { name: row.get::("index_name"), - columns: all_cols, + columns: key_cols, is_unique: row.get::("is_unique"), is_primary: row.get::("is_primary"), filter: row.get::, _>("filter_expr"), diff --git a/src-tauri/src/db/sqlserver.rs b/src-tauri/src/db/sqlserver.rs index 47d54c0bfe..bcc03092a0 100644 --- a/src-tauri/src/db/sqlserver.rs +++ b/src-tauri/src/db/sqlserver.rs @@ -125,7 +125,12 @@ pub async fn get_columns(client: &mut SqlServerClient, schema: &str, table: &str Some(n) => format!("nvarchar({n})"), None => "nvarchar".to_string(), }, - "char" | "nchar" | "binary" | "varbinary" => match max_len { + "varbinary" => match max_len { + Some(-1) => "varbinary(max)".to_string(), + Some(n) if n > 0 => format!("varbinary({n})"), + _ => "varbinary".to_string(), + }, + "char" | "nchar" | "binary" => match max_len { Some(n) if n > 0 => format!("{base}({n})"), _ => base, }