fix(postgres): bind the caller's schema in getTableColumns - #60
Merged
Conversation
getTablesAndViews() passes the schema each table was found in, but the method
bound DEFAULT_SCHEMA ('public'), so every table on a database whose objects live
outside public came back with zero columns. Measured on isha_data_clean:
marts.dim_person returns 91 columns when bound to 'marts', 0 when bound to
'public'.
The PK subquery also had no schema predicate at all. Postgres auto-names primary
keys '<table>_pkey', so two schemas holding a same-named table cross-match by
construction. Adds tc.table_schema = ku.table_schema and ku.table_schema = ?.
Local-only until PR #40 resolves its conflict with the multi-schema work in #55.
Contributor
|
Looks good — approve. |
venkateshsakamuri-lab
approved these changes
Aug 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getTablesAndViews()passes the schema each table was found in, butgetTableColumnsboundDEFAULT_SCHEMA('public') and discarded the argument. Every table on a database whose objects live outsidepubliccame back with zero columns.Measured against a real dbt warehouse (195 tables across 17 schemas, nothing in
public):The PK subquery also had no schema predicate at all. Postgres auto-names primary keys
<table>_pkey, so two schemas holding a same-named table cross-match by construction — producing duplicatedColumnInforows and false-positive PK flags. This addstc.table_schema = ku.table_schemaandku.table_schema = ?.Both problems were latent while the provider only ever read
public. #55 made them live: now that introspection walks every non-system schema, astaging/marts/publiccollision onordersorcustomersis the normal shape of a dbt warehouse, not the exception.Verification
Deployed and measured on a live 195-table warehouse:
A full brain re-init on that connection went from a 37-table snapshot to 195 tables / 4,070 columns, lifting
table_classification25 → 161 andinferred_table_relationship17 → 280. The agent went from being blind to 14 of 18 schemas to correctly describing them.Unit tests:
PostgresIntrospectionProviderTestpasses. A mockedResultSetcan't exercise SQL semantics, so the correctness evidence is the measurement above, against Postgres 18.Relationship to #40
#40 is open and
CONFLICTING. It fixed the same class of problem with acurrent_schema()approach that #55 superseded by scanning all non-system schemas. This PR sits on top of #55 instead and is independent of #40 — #40 can likely be closed once this lands.