Add support for materialized views in the preview table dropdown when creating or editing a query.
Add support for materialized views in the preview table dropdown when creating or editing a query. This addition is only for PostgreSQL.
This PR is related to this issue #81 It's not on the Ideas issue #24 so I'm not sure if you are still interested in adding this to Blazer.
Thanks again and this is a really great project!
Hey @strivedi183, thanks for the PR! Happy to include this feature, but I think it'll be a bit more work. The current query doesn't take into account:
- If the Blazer user has privileges for the materialized views
- The schema settings (applied by the
add_schemasmethod)
I think the query below will cover the first one (based on the query for the information_schema.tables view).
UNION ALL (
SELECT n.nspname as table_schema, c.relname as table_name
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind = 'm' AND
(
pg_has_role(c.relowner, 'USAGE')
OR has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
OR has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES')
)
)
We'll need to add the materialized view columns to the schema method as well.
Thank you for your feedback and help @ankane !
I tried to take into account both things you mentioned.
For 1), your query worked like a charm!
For 2), using the above query as a base, I used pg_attribute.attname to get the column_name, pg_type.typname to get the data_type, pg_attribute.attnum to get the ordinal_position.
It isn't an exact 1-1 match for the data_type naming, since pg_type.typname sometimes uses different names for the same type like int4 and int8 instead of integer. The types are still correct, just not consistent naming between tables and materialized views.
Thank you again!
Hi @ankane , we've been running this in production for the past few months and we haven't had any issues.
After you get a chance to review, if there are any other issues, more than happy to fix them.
Thanks again!
Is there is anything left that would be necessary to do to make this merge-able? Would be a super useful feature for me, happy to contribute.
Ditto on the above, this would be very useful