Fixed width string formatting for variable values

  • What Grafana version and what operating system are you using?

10.2.3

  • What are you trying to achieve?

I am looking up the integer id number of a named quantity in a PostgreSQL table - this is done via a drop down variable where I select the name of the variables loaded from this table. This id number is used in the name of the TimescaleDB table for that variable, named in the
format var_${vartid:06d}

I am then trying to graph the variable, using:
SELECT time, c0 AS "${name}" FROM var_${vartid:06d}

  • What happened?

db query error: pq: relation "var_153" does not exist

Clearly this kind of string formatting is not supported (in this syntax, at least).

  • What did you expect to happen?

A query of the var_000153 table

Is this kind of basic string formatting available in Grafana, either in variable definitions or graph definitions? Googling hasn’t really turned up anything relevant so far.

That’s not available:

Use additional hidden variable, where you will format it with SQL, e.g. SELECT FORMAT($variable) (check your sql doc for proper syntax and function which are available). And then used that properly fornatted variable.