PostgresSQL query for multiple variables in a single panel

  • What Grafana version and what operating system are you using?
    Grafana OSS v9.0.3 on Linux

  • What are you trying to achieve?
    I’m trying to build a panel in grafana using postgres connector and multiple variable select without having to go through pgplsql if possible

my variable is a list of uuids

I want to run a simple select * ${variable_id}.table_name where the uuid is the schema name.

Using a single variable selected, this works but once I select multiple it obviously breaks

Is there a way to loop over the selected variables, run the query above all in one single panel without using the repeat panel option? trying to do a ‘rollup’ view of sorts all in one panel

(e.g in pseudo code):

for var in ${variables}
  select * from var."table_name"
end

Welcome @ks2211

You have uuids as schema? Why such design?

Anyways try to use a stored procedure and do your logic in the spric would be my recommendation

Pass the var as command delimited or something like that

Hey @yosiasz thanks for the response.

Is it possible to loop over variables in grafana? Was trying to avoid the stored procedure if possible but if thats my only option, I’ll go that route

Yes you could loop but depends on what the final visualization you want to see

Please post the data from thr select query and how and what you to display

@yosiasz I’m trying to visualize a table.

id| variable_id | name

uuid1|variable_uuid1|test
uuid2|variable_uuid2|test2
uuid3|variable_uuid2|test3
uuid3|variable_uuid3|test4

all of the schemas have the same table structure so im trying to loop over the multiple selected variables, run the same query and combine all of the data into a single panel

so if I were to manually add queries, it would look something like

select * from variable_uuid1.table_a
select * from variable_uuid2.table_a
select * from variable_uuid3.table_a
etc

i was going to recommend using dynamic text plugin but seeing this schema design I would go with stored procedure.