Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for materialized views in the preview table dropdown when creating or editing a query. #282

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

strivedi183
Copy link

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!

table dropdown when creating or editing a query.
This addition is only for PostgreSQL.
@ankane
Copy link
Owner

ankane commented Apr 11, 2020

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:

  1. If the Blazer user has privileges for the materialized views
  2. The schema settings (applied by the add_schemas method)

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.

Take into account both making sure the Blazer user has privileges for
the materialized views and the schema settings.
This improvement is only for PostgreSQL.
@strivedi183
Copy link
Author

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!

@strivedi183
Copy link
Author

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!

@notactuallytreyanastasio
Copy link

notactuallytreyanastasio commented Jan 6, 2021

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.

@Aemrox
Copy link

Aemrox commented Jan 13, 2021

Ditto on the above, this would be very useful

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.

4 participants