Help with templating variables in MySQL

So within my database(r) I’ve got 5 tables(a,b,c,d,e) and I want to be able to show the amount of packets stored at the current time(created_at) with any combination of them on a graph…

  1. I have a Custom variable for the table name($table_name):
    r.a, r.b, r.c, r.d, r.e
    and I have multi-select and all checked…

  2. Next I have a Custom variable with the column names($col_name):
    a.created_at, b.created_at, c.created_at, d.created_at, e.created_at
    and I have multi-select and all checked…

  3. So from there I constructed the following:

     NOW() as time,
     count(${col_name:format}) as value,
     'packets' as metric
     FROM ${table_name:format}
     GROUP BY 3

The column name I’m trying to return for each of the tables is named the same, it’s simply a created_at column and I’m just trying to take the count of it to return the number of data entries. When I left that select parameter as:
count(created_at) as value,
I was getting an error "column ‘created_at’ is ambiguous’ so I figured specifying the table name would fix this, but I’m continuing to just hit syntax errors… Am I missing something about the syntax of MySQL? Is this an issue with the language limitations? The issue came in with trying to use the variable in the SELECT statement for the value, aside from the “created_at is ambiguous” the FROM ${table_name:format} should be fine. Any help would be awesome.

Could you finally solve it?

Unfortunately not, I worked on it for a good portion of that day, but it really doesn’t like the variable formatting for the indices called within the SELECT statement… MySQL seems loosely supported on Grafana, many of the seemingly core features have convoluted workarounds, so I’m putting the Grafana work on hold for now as this is one of the last features I was planning to implement.