I looking for a way to define sql filter values as a dashboard variable.
The variables with the filter statement look like this
All: LIKE ‘%’
Extern: IN(‘1111’,‘2222’)
Intern: NOT IN(‘1111’,‘2222’)
Depending on the selected filter the where clause in the sql statement should look like this:
For selected value extern: SELECT .... WHERE (id= 'test' AND type NOT IN('1111','2222') and $__timeFilter(timestamp))
or for selected value intern: SELECT .... WHERE (id= 'test' AND type IN('1111','2222') and $__timeFilter(timestamp))
Unfortunatly custom variables with key value pairs can not be used because of the comma separated sql statement and if you use single quotes in a variable it will be “single quoted” again in the sql statement.
You can use it, just escape that comma. IMHO: \,
Escape also other special characters, which may be misinterpreted by variable definition.
Use :raw variable value in SQL, otherwise Grafana may add own escaping/quoting there, which will break SQL syntax.
Thanks, It does work when i only define values like that
IN(‘1111’,‘2222’)
NOT IN(‘1111’,‘2222’)
When i define it as key :values i can’t read only the value in the sql statement.
I tried this in my sql statement ${my_variable:value:raw} but it always return the key and the value. Is this the correct syntax?