diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue index 4e297b3e7d..da13cce455 100644 --- a/apps/desktop/src/components/editor/QueryEditor.vue +++ b/apps/desktop/src/components/editor/QueryEditor.vue @@ -1117,7 +1117,7 @@ async function performAsyncCompletionWithResult(epoch: number, completionContext // If qualifier didn't match any table names, try it as a schema name let qualifierIsSchema = false; - if (completionContext.qualifier && tables.length === 0 && (completionContext.suggestTables || completionContext.exclusiveColumnSuggestions)) { + if (completionContext.qualifier && !isReferencedTableQualifier(completionContext) && tables.length === 0 && (completionContext.suggestTables || completionContext.exclusiveColumnSuggestions)) { const schemaTables = await connectionStore.listCompletionTables(props.connectionId!, props.database!, completionContext.prefix, MAX_COMPLETION_TABLES, completionContext.qualifier); if (schemaTables.length > 0) { tables = schemaTables; diff --git a/packages/app-tests/sqlCompletion.test.ts b/packages/app-tests/sqlCompletion.test.ts index a6c4af88da..217a76fd17 100644 --- a/packages/app-tests/sqlCompletion.test.ts +++ b/packages/app-tests/sqlCompletion.test.ts @@ -262,6 +262,46 @@ test("keeps explicit alias column suggestions scoped to the alias table", () => ); }); +test("does not show table names after an explicit alias qualifier", () => { + const sql = "select * from billing_owner b where b."; + const items = buildSqlCompletionItems(sql, sql.length, { + tables: [ + { name: "base_gateway_expand", schema: "BU", type: "table" }, + { name: "billing_owner", schema: "BU", type: "table" }, + ], + columnsByTable: new Map(), + }); + + assert.deepEqual(items, []); +}); + +test("suggests columns after an explicit alias qualifier without leaking tables", () => { + const sql = "select * from billing_owner b where b."; + const items = buildSqlCompletionItems(sql, sql.length, { + tables: [ + { name: "base_gateway_expand", schema: "BU", type: "table" }, + { name: "billing_owner", schema: "BU", type: "table" }, + ], + columnsByTable: new Map([ + [ + "BU.billing_owner", + [ + { name: "owner_id", table: "billing_owner", schema: "BU", dataType: "number" }, + { name: "owner_name", table: "billing_owner", schema: "BU", dataType: "varchar" }, + ], + ], + ]), + }); + + assert.deepEqual( + items.map((item) => [item.label, item.type, item.detail]), + [ + ["owner_id", "column", "BU.billing_owner [number]"], + ["owner_name", "column", "BU.billing_owner [varchar]"], + ], + ); +}); + test("shows column comments in WHERE field completions", () => { const sql = "select * from public.orders where st"; const items = buildSqlCompletionItems(sql, sql.length, {