Skip to content

Add PostgreSQL materialized view support#513

Open
jamesbrink wants to merge 1 commit intoankane:masterfrom
jamesbrink:feat/matview-support-final
Open

Add PostgreSQL materialized view support#513
jamesbrink wants to merge 1 commit intoankane:masterfrom
jamesbrink:feat/matview-support-final

Conversation

@jamesbrink
Copy link

Summary

This PR adds support for PostgreSQL materialized views in Blazer's:

  • Table preview dropdown - Materialized views now appear alongside tables when creating/editing queries
  • Schema explorer page - Materialized views and their columns are now displayed in the schema browser

This addresses a long-standing feature request that has been open for nearly 5 years.

Related Issues & PRs

Implementation

SqlAdapter.tables() changes

  • Added PostgreSQL-specific branch that queries pg_class with relkind = 'm' for materialized views
  • Uses UNION ALL to combine with existing information_schema.tables query
  • Includes privilege check via has_table_privilege() to only show accessible matviews

SqlAdapter.schema() changes

  • Added PostgreSQL-specific branch that queries pg_attribute for materialized view columns
  • Uses format_type() for human-readable column data types
  • Includes privilege check for security

Key design decisions

  • Minimal changes - Only PostgreSQL is affected; other adapters unchanged
  • Security - Respects database privileges via has_table_privilege()
  • Schema filtering - Works with existing schemas config setting
  • Backward compatible - No changes to output format or API

Test Plan

  • Added 8 new tests for materialized view functionality
  • Tests verify matviews appear in tables list with correct format
  • Tests verify matviews appear in schema with correct columns
  • Tests verify queries against matviews execute correctly
  • All existing tests continue to pass (71 runs, 0 failures)
  • PostgreSQL adapter tests pass (28 runs, 0 failures)
  • SQLite adapter tests pass (13 runs, 0 failures)

Screenshots

N/A - Backend changes only, no UI modifications needed.

Materialized views now appear in:
- Table preview dropdown when creating/editing queries
- Schema explorer page with column information

Implementation:
- Modified SqlAdapter.tables() to include pg_matviews via UNION ALL
- Modified SqlAdapter.schema() to include matview columns via pg_attribute
- Added privilege checks (has_table_privilege) to only show accessible matviews
- Uses format_type() for human-readable column data types

Addresses PR ankane#282 and Issue ankane#498 from upstream.

Test coverage:
- 8 new tests for materialized view functionality
- Tests verify matviews appear in tables list and schema
- Tests verify column information is correct
- Tests verify queries against matviews work
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.

Views and materialized Views not displayed in schema page

1 participant