4

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?

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, the trouble with this approach is that NULL isn't always selected in the dashboard as an option for the variable. I essentially need the IS NULL clause to be conditional if a null value is selected in the list of options in the dashboard drop down.
@radicand There are other options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.