Query on variables to select all column

I´m trying to create a query based on Postgresql creating a variable that should select all values from the chosen column (temperature, turbidity, dissolved O2, etc ). Is there somekind of example in that case?

Can you provide me with demo data and screenshots related to this?

you could create a dynamic query (not best option) or a view (best option)

view option

CREATE VIEW shabba_ranks AS
    SELECT temperature as value, 'temperature' as metric
        FROM table 
    union
    select  turbidity as value, 'turbidity' as metric
    from table 
    union
   select  'dissolved O2' as value, 'dissolved O2' as metric
   from table

So this design assumes a few things, you have these in one table but we don’t know that since you didn’t provide the schema details of table(s)

Then in grafana you use

select value from shabba_ranks where metric = $column_variable

but this approach itself might not be the best approach but it depends on your table setup etc.

1 Like

Hello @yosiasz and @infofcc3, thanks for the reply! Unfortunately, I am no longer at the company where I took on the challenge.

1 Like