Skip to content

fix(plugin-postgresql): complete autocomplete for tables and columns in non-active schemas (#1668)#1674

Merged
datlechin merged 2 commits into
mainfrom
fix/cross-schema-autocomplete-1668
Jun 13, 2026
Merged

fix(plugin-postgresql): complete autocomplete for tables and columns in non-active schemas (#1668)#1674
datlechin merged 2 commits into
mainfrom
fix/cross-schema-autocomplete-1668

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #1668.

Problem

PostgreSQL autocomplete only completed tables and columns from the schema selected in the sidebar. A schema-qualified query like SELECT * FROM s2.orders got no completions for s2's columns when s1 was the active schema.

Root cause

The completion engine threads the referenced schema all the way down (parser, SQLSchemaProvider, SchemaProviderRegistry), but the drivers discarded it on the last hop:

  • PostgreSQLPluginDriver.fetchColumns / fetchAllColumns hardcoded currentSchema ?? "public" and ignored their schema parameter.
  • Redshift routed every schema-scoped method through an escapedSchema convenience pinned to currentSchema, so its cross-schema completion failed for both tables and columns.

CockroachDB (same plugin bundle) already resolved schema ?? currentSchema correctly and was the reference.

Fix

  • Honor the requested schema (schema ?? currentSchema) in the PostgreSQL and Redshift column/structure queries.
  • Removed the escapedSchema footgun from LibPQBackedDriver and threaded the parameter through every method that used it (columns, foreign keys, DDL, view definitions, table metadata, dependent types/sequences).
  • Extracted the column SQL into pure builders (PostgreSQLSchemaQueries.columnsQuery, RedshiftSchemaQueries.columnsQuery) so the schema-threading is unit-tested.

No PluginKit ABI change (all changes are internal to the PostgreSQL plugin bundle).

Tests

New PostgreSQLColumnQueryTests covers both builders: the requested schema (including non-active schemas) threads into the WHERE and PK clauses, single-table vs all-tables shapes are correct. The builders compile into the test target via the existing PluginTestSources symlink mechanism, so they run without the libpq C bridge.

Notes

  • Docs already document schema-qualified resolution as working (docs/features/autocomplete.mdx); this makes PostgreSQL match the docs.
  • Out of scope: fetchIndexes has a separate, pre-existing missing-schema-filter ambiguity (not autocomplete, not the escapedSchema footgun).

@datlechin datlechin merged commit 90d5b32 into main Jun 13, 2026
3 of 4 checks passed
@datlechin datlechin deleted the fix/cross-schema-autocomplete-1668 branch June 13, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autocomplete Does Not Work Across Multiple Schemas

1 participant