Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grafana dashboard variable - handling NULL values in Query-based variable

I've created a Grafana dashboard variable (multi-select enabled) based on a MySQL query:

SELECT DISTINCT(my_field) from my_table

This field has about 12 options, one of them being a NULL value. When editing my dashboard widgets, I include a SQL constraint similar to:

... WHERE my_field IN ($my_variable)

This almost works well, except for the NULLs. Grafana is translating the NULL to '', and NULL isn't supported in an IN (...) statement anyway.

Any recommendations on how to handle this to work with NULLs?

like image 804
radicand Avatar asked Oct 22 '25 14:10

radicand


1 Answers

You could extend condition:

WHERE my_field IN ($my_variable) OR my_field IS NULL;

Grafana is translating the NULL to ''

WHERE COALESCE(my_field, '') IN ($my_variable)
like image 118
Lukasz Szozda Avatar answered Oct 25 '25 06:10

Lukasz Szozda