Variable interpolation with 'IN' clause for POSTGRES DB

Grafana version: 7.4.3
I am trying to write a query with ‘IN’ clause to create chart based on multi value selection filter. I used following query with variable interpoloation:
‘’’
SELECT
$__time(timestamp),
hostname as metric,
avg((metrics->‘memory’->‘HeapMemoryUsage’->>‘used’)::bigint)as value
FROM
public.metrics
WHERE
$__timeFilter(timestamp) and hostname in (’${hostList:csv}’)
group by time, hostname
order by time
‘’’
Expected result:
‘’’
SELECT
timestamp AS “time”,
hostname as metric,
avg((metrics->‘memory’->‘HeapMemoryUsage’->>‘used’)::bigint)as value
FROM
public.metrics
WHERE
timestamp BETWEEN ‘2021-03-04T21:34:15.371Z’ AND ‘2021-03-05T21:34:15.371Z’ and hostname in (‘a’, ‘b’, ‘c’)
group by timestamp, hostname
‘’’
What I get is:
‘’’
SELECT
timestamp AS “time”,
hostname as metric,
avg((metrics->‘memory’->‘HeapMemoryUsage’->>‘used’)::bigint)as value
FROM
public.metrics
WHERE
timestamp BETWEEN ‘2021-03-04T21:34:15.371Z’ AND ‘2021-03-05T21:34:15.371Z’ and hostname in (‘a, b, c’)
group by timestamp, hostname
‘’’

Use better variable formatting, singlequote in your case and not csv.

This topic was automatically closed after 365 days. New replies are no longer allowed.