I am using a MySQL datasource, I have a template variable, and in the query I want to use the template variable in a WHERE clause with the LIKE operator.
For example: WHERE Summary LIKE %$variable%
But this doesn’t work, the resulting SQL is: WHERE Summary LIKE %"variable"%
I can work around it crudely by adding the % to the custom variables, so instead of say “server1” I put “%server1%”. Is there any better way to deal with this? The problem seems to be that Grafana automatically adds the quotes around the variable but only the variable. It would be nice is there was maybe an escape character that told Grafana not to automatically add quotes.
Hi,
i’ve just updated to Grafana 4.6 beta 2 and trying to use SQL Queries as template variables in SQL Queries.
There is still the problem of the quoted template variables!
When it’s going to be fixed? Is there a work around?
Edit: i found a solution by calling a stored proc in the variables query with the other variable(string) as in parameter.
in the stored proc i can concat the string to a query and execute.
SQL statement:
SELECT UNIX_TIMESTAMP(metric_time) as time_sec,
metric_value as value,
metric_key as metric
FROM COBOL_COMP_TREND
WHERE $__timeFilter(metric_time)
AND SWSC= '%var-SWSC%'
ORDER BY metric_time ASC
sql used by grafana:
rawSql:"SELECT UNIX_TIMESTAMP(metric_time) as time_sec, metric_value as value, metric_key as metric FROM COBOL_COMP_TREND WHERE $__timeFilter(metric_time) AND SWSC= ‘%var-SWSC%’ ORDER BY metric_time ASC"
format:“time_series”