Skip to content

Exclude views from get_table_names() - #310

Open
aminghadersohi wants to merge 2 commits into
cockroachdb:masterfrom
aminghadersohi:get-table-names-exclude-views
Open

aminghadersohi wants to merge 2 commits into
cockroachdb:masterfrom
aminghadersohi:get-table-names-exclude-views

Conversation

@aminghadersohi

@aminghadersohi aminghadersohi commented Sep 26, 2026 •

Copy link
Copy Markdown

get_table_names() selects every row of information_schema.tables for the schema, so views are returned as tables in addition to being returned by get_view_names(). SQLAlchemy defines get_table_names() as base tables only; applications that list tables and views separately show each view twice.

This filters on table_type = 'BASE TABLE'. has_table() previously delegated to get_table_names(); it now checks all relations directly, so it still returns True for views, as SQLAlchemy 2.0 specifies. The pre-v2 SHOW TABLES branch is unchanged. A CHANGES.md entry is added under the unreleased 2.0.5 section.

Tests (test/test_introspection.py::TableNamesTest), against CockroachDB v24.3.0 single node:

  • before this change: test_get_table_names_excludes_views fails (assert 'names_view' not in ['names_base', 'names_view']); 1 failed, 17 passed
  • after: 18 passed

The test_suite_sqlalchemy.py reflection subset (-k "table_names or has_table or view_names or get_multi") has an identical set of 9 pre-existing failures (test_get_multi_foreign_keys variants and one test_get_table_names[...foreign_key...]) with and without this change; 123 pass in both.

get_table_names() read every row of information_schema.tables for the
schema, so views were returned as tables as well as by get_view_names().
SQLAlchemy defines get_table_names() as base tables only, and callers
that list tables and views separately showed each view twice.

Filter on table_type = 'BASE TABLE'. has_table() previously relied on
get_table_names(); it now checks all relations directly, so it keeps
returning True for views as SQLAlchemy 2.0 specifies.
@gordthompson gordthompson self-assigned this Sep 27, 2026
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.

2 participants