Skip to content

fix(postgres): include foreign tables in search_objects - #419

Merged
tianzhou merged 1 commit into
mainfrom
claude/issue-418-verdict-0dfe1u
Sep 8, 2026
Merged

fix(postgres): include foreign tables in search_objects#419
tianzhou merged 1 commit into
mainfrom
claude/issue-418-verdict-0dfe1u

Conversation

@tianzhou

@tianzhou tianzhou commented Sep 8, 2026

Copy link
Copy Markdown
Member

Closes #418

Problem

Postgres reports foreign tables (postgres_fdw, file_fdw, ...) in information_schema.tables with table_type = 'FOREIGN'. The Postgres connector's getTables filtered on table_type = 'BASE TABLE' only, so search_objects never listed foreign tables, and the column search (which builds its list from getTables + getViews) never listed their columns either.

This was an enumeration-only gap: every per-table detail query already handled foreign tables. getTableSchema reads information_schema.columns (which includes them), getTableRowCount and getTableComment already accept relkind = 'f', and tableExists has no type filter. An agent that already knew the name could describe and query the table but could not discover it.

Changes

  • src/connectors/postgres/index.ts
    • getTables: filter on table_type IN ('BASE TABLE', 'FOREIGN').
    • getTableIndexes: accept relkind IN ('r','p') instead of 'r' only, so partitioned tables (which carry their own index entries since PG11) report their indexes. Foreign tables cannot have indexes and correctly return an empty list.
  • src/connectors/__tests__/postgres.integration.test.ts: fixture creates a foreign table on a handler-less foreign data wrapper (no extension or remote server needed; catalog entries exist and can be enumerated/described, the table just can't be scanned). New tests assert the foreign table appears in getTables, not in getViews, passes tableExists, and that getTableSchema, getTableComment, and getTableIndexes behave like they do for regular tables.
  • src/connectors/__tests__/shared/integration-test-base.ts: comment wording only.

No change to other connectors (no equivalent concept in MySQL/MariaDB/SQL Server/SQLite) or to the Connector interface contract (getTables still excludes views).

Not included

Materialized views are also missing from both getTables and getViews because information_schema.tables omits them entirely. Fixing that properly also requires changing getTableSchema, since information_schema.columns does not describe materialized views. Left for a follow-up to keep this change scoped to the issue.

Testing

  • pnpm run test:unit: 997 tests pass.
  • tsc --noEmit: clean.
  • Integration tests require Docker, which was not available in the authoring environment; the new Postgres integration tests will run in CI.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Yc1YYa3jHCEW7FDxC66R9Z


Generated by Claude Code

…can discover them

Postgres reports foreign tables (postgres_fdw, file_fdw, ...) in
information_schema.tables with table_type = 'FOREIGN', so the
'BASE TABLE' filter hid them from search_objects even though every
per-table detail query (columns, comment, row count, tableExists)
already handled them. Widen the filter to include 'FOREIGN'.

Also let getTableIndexes see partitioned tables (relkind 'p'), which
carry their own index entries since PG11 but were filtered out.

Adds integration coverage using a handler-less FDW so the foreign
table can be enumerated and described without a remote server.

Closes #418

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Yc1YYa3jHCEW7FDxC66R9Z
Copilot AI lite review requested due to automatic review settings September 8, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are small, scoped to Postgres metadata enumeration, and are supported by targeted integration tests covering the new foreign-table behavior.

Pull request overview

This PR fixes a Postgres connector discovery gap so search_objects can enumerate foreign tables (FDW-backed) and their columns by ensuring getTables() includes information_schema.tables.table_type = 'FOREIGN', and it also improves index enumeration for partitioned tables.

Changes:

  • Update Postgres getTables() to include table_type IN ('BASE TABLE', 'FOREIGN') so foreign tables become discoverable.
  • Update Postgres getTableIndexes() to include partitioned tables (relkind IN ('r','p')) when enumerating indexes.
  • Add Postgres integration coverage for foreign-table discovery/description behavior; adjust shared integration-test comment wording.
File summaries
File Description
src/connectors/postgres/index.ts Expands table discovery to include foreign tables and broadens index enumeration to cover partitioned tables.
src/connectors/tests/postgres.integration.test.ts Adds integration tests and fixtures to validate foreign table discovery and description behavior.
src/connectors/tests/shared/integration-test-base.ts Comment wording update to reflect getTables() semantics (tables only, never views).
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tianzhou
tianzhou merged commit cca7b67 into main Sep 8, 2026
3 checks passed
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.

search_objects should return foreign tables

3 participants