fix: cross schema table reference in view#105
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes cross-schema table references in views by ensuring that pg_get_viewdef() properly qualifies table references from different schemas. The fix modifies the database query to temporarily set search_path to only the view's schema, forcing PostgreSQL to include schema qualifiers for cross-schema references. The parser and formatter are also updated to apply the same qualification rules.
- Modified the
GetViewsForSchemaquery to useset_configfor temporarysearch_pathmanipulation - Updated the formatter to apply schema qualification rules (omit for same-schema, include for cross-schema)
- Threaded
viewSchemaparameter through parser and normalization functions
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/dump/tenant/pgschema.sql | Adds test data with materialized view and regular view that reference cross-schema tables |
| ir/queries/queries.sql.go | Generated code reflecting the updated SQL query with search_path manipulation |
| ir/queries/queries.sql | Modified query to use CTE and set_config to control schema qualification in view definitions |
| ir/parser.go | Updated function signatures to accept and pass viewSchema parameter |
| ir/normalize.go | Updated normalization functions to accept and pass viewSchema parameter |
| ir/formatter.go | Implements schema qualification logic based on whether table and view schemas match |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
634acba to
9aad7f4
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Fix #102