Setting variables, views, postgreSQL

Grafana version. 8.5.2

Not sure if this is possible, so I´m reaching out.

We have identical views in our postgresql db - only the name of the views differs.
How can we set a variable like this when we quickly want to select one of filtered values in the drop down menu?:

select ts as time, attr1,attr2, attr3 from my_scheme.$my_view_variable_here where ....;

We´ve tried setting up a query in Variables getting all the possible values from the table (where views are build from) using it as variabel in panel with multiple syntaxes, but without succes. Is it even possible?

Thank you,

Welcome

so you want to dynamically do a query from a view and the view name is coming from a drop down variable?

My first question to you is why are you using this design approach with 2 views with different names but are identical on the inside?

Are you testing some functionality out?

THanks

Hi
@yosiasz thanks for reply.

so you want to dynamically do a query from a view and the view name is coming from a drop down variable?

Not a query from a view, but a variable giving me the option to select one of many views. Almost similiar to this approach.

The structure of the views are the same and there are many of them - the data is not. The reason for the design is the goal of building a dashboard template where I easily can shift between views in the db

Hi @yosiasz
Thanks for the reply.

so you want to dynamically do a query from a view and the view name is coming from a drop down variable?

No. What I need is to make a template. I need to set a variable that gives me the option to select between multiple views in the database. The views structure are identical - but not the data. Something similar to this setup (See Templates section).

you can make variable using variable.

Your first var is your list of database name (hadock text ),
second var is list of your view (query ) using first var.

I know how to make variables. I found the solution. Hope this helps others.

Query for variable looking up accesable views in database is:

select  viewname from pg_catalog.pg_views
where schemaname NOT IN ('pg_catalog', 'information_schema', 'public')
order by schemaname, viewname;

Query, panel SQL query
select ts as time, attr1,attr2, attr3 FROM my_scheme.${variable_name:raw};