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

Postgres - Materialized Views are not handled like tables #27017

Closed
farthinder opened this issue Aug 15, 2020 · 3 comments
Closed

Postgres - Materialized Views are not handled like tables #27017

farthinder opened this issue Aug 15, 2020 · 3 comments

Comments

@farthinder
Copy link

farthinder commented Aug 15, 2020

What happened:
Postgres materialized views don't show up as selectable tables and neither does their columns when setting up a panel.
Inputting the names of the tables and columns manually does work

What you expected to happen:
I expected that when setting up a new panel, when in the query definition tab that the "From" field should be populated with "new_mview" and the the columns "timestamp" and "valueColoumn" should be populated as possible columns to select.

How to reproduce it (as minimally and precisely as possible):
This is my sample definition for a materialized view that I expected Grafana to find:

CREATE MATERIALIZED VIEW public.new_mview
TABLESPACE pg_default
AS 
SELECT now() AS timestamp, 100 as valueColoumn
WITH DATA;

Anything else we need to know?:

I looked at the discovering query that Grafana sends to the DB-server:

SELECT quote_ident(table_name) FROM information_schema.tables WHERE
table_schema IN (
  SELECT
    CASE WHEN trim(s[i]) = '"$user"' THEN user ELSE trim(s[i]) END
  FROM
    generate_series(
      array_lower(string_to_array(current_setting('search_path'),','),1),
      array_upper(string_to_array(current_setting('search_path'),','),1)
    ) as i,
    string_to_array(current_setting('search_path'),',') s
) ORDER BY table_name

This query seems to be built by: meta_query.ts

This returns normal tables and "normal views" but not materialized views. To query postgres for the materialized views you can use the query:
select * from pg_matviews;

I raised a forum post about the problem here: https://community.grafana.com/t/postgres-materialized-view-autocomplete/35081

Environment:

  • Grafana version: v7.1.3
  • Data source type & version: Postgres 10.12
  • OS Grafana is installed on: Ubuntu 20 LTS
  • User OS & Browser: OSX, Firefox
  • Grafana plugins: Default only
  • Others:
@farthinder
Copy link
Author

While looking in to this I noticed that this discovery query and it´s findings doesn't seem to get logged to the log file even when:

[log]
level = debug
[log.file]
level = debug
[database]
log_queries = true

Not sure if that can be considered a bug, but I expected that to be part of the output.

jdbranham added a commit to savantly-net/grafana that referenced this issue Sep 6, 2020
MView information is stored in a different system table, so the current
implemention doesn't offer suggestions.
A union query is performed to get all tables plus mviews.
This PR adds table 'type' property to the ctrl target to identify MVIEW from TABLE.
This allows us to use the correct system tables to get column information.

resolves: grafana#27017
@mdvictor
Copy link
Contributor

I will close this as it has been fixed by this

@jasonvasquez
Copy link

Hello - while testing in grafana 9.5.13, I can see that regular views are indeed visible, but postgres materialized views are not visible. Is that expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants