Skip to content

fix: cross schema table reference in view#105

Merged
tianzhou merged 1 commit intomainfrom
cross_schema_table_reference_in_view
Oct 20, 2025
Merged

fix: cross schema table reference in view#105
tianzhou merged 1 commit intomainfrom
cross_schema_table_reference_in_view

Conversation

@tianzhou
Copy link
Contributor

Fix #102

Copilot AI review requested due to automatic review settings October 20, 2025 16:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 GetViewsForSchema query to use set_config for temporary search_path manipulation
  • Updated the formatter to apply schema qualification rules (omit for same-schema, include for cross-schema)
  • Threaded viewSchema parameter 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.

@tianzhou tianzhou force-pushed the cross_schema_table_reference_in_view branch from 634acba to 9aad7f4 Compare October 20, 2025 16:58
@tianzhou tianzhou requested a review from Copilot October 20, 2025 16:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@tianzhou tianzhou merged commit 2d417e0 into main Oct 20, 2025
2 checks passed
@tianzhou tianzhou deleted the cross_schema_table_reference_in_view branch October 23, 2025 06:34
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.

cross-schema table references in views should be fully qualified

2 participants