Postgresql : Concatenate variable for querying

Hello Everyone,

Version:

Postgresql : PostgreSQL 14.5
TimescaleDB: 2.8.1
Grafana: 9.3.1

I am using Grafana for visualizing some zabbix metrics with a custom database setup and I don’t find any solution to query a metrics when require string and template variable data concatenation.

For exemple, this query work when i select only one var in template variable “fs” :

SELECT
  i.hostname,
  $__timeGroup(hui.time,'1m', previous) at time zone 'Europe/Paris' as time,
  i.name AS item,
  AVG(hui.value) AS value
FROM
  metrics.metro_items i
  INNER JOIN metrics.metro_history_uint hui ON i.itemid = hui.itemid
WHERE
  i.name = '${fs:raw}: Total space'
  AND i.hostname in([[hostname]])
  AND hui.time BETWEEN ('${__from:date}' at time zone 'Europe/Paris') AND ('${__to:date}' at time zone 'Europe/Paris')
GROUP BY 1,2,3
ORDER BY time ASC

query inspector result :

SELECT
  i.hostname,
  time_bucket('60.000s',hui.time) at time zone 'Europe/Paris' as time,
  i.name AS item,
  AVG(hui.value) AS value
FROM
  metrics.metro_items i
  INNER JOIN metrics.metro_history_uint hui ON i.itemid = hui.itemid
WHERE
  i.name = '/var: Total space'
  AND i.hostname in('vteslprbd00034-2')
  AND hui.time BETWEEN ('2023-01-06T23:00:00.000Z' at time zone 'Europe/Paris') AND ('2023-01-07T00:00:00.000Z' at time zone 'Europe/Paris')
GROUP BY 1,2,3
ORDER BY time ASC

But when I want to select more than one variable (‘/’ + ‘/var’), the query format isn’t correct :

Query inspector result :

SELECT
  i.hostname,
  time_bucket('60.000s',hui.time) at time zone 'Europe/Paris' as time,
  i.name AS item,
  AVG(hui.value) AS value
FROM
  metrics.metro_items i
  INNER JOIN metrics.metro_history_uint hui ON i.itemid = hui.itemid
WHERE
  i.name = '/var,/: Total space'
  AND i.hostname in('vteslprbd00034-2')
  AND hui.time BETWEEN ('2023-01-06T23:00:00.000Z' at time zone 'Europe/Paris') AND ('2023-01-07T00:00:00.000Z' at time zone 'Europe/Paris')
GROUP BY 1,2,3
ORDER BY time ASC

I tried different solutions like CONCACT without success.
Is there any native solution on grafana to archieve it ?

Thank you