Problems with mulptiple time series from variable

  • What Grafana version and what operating system are you using?
    V9.3.2

  • What are you trying to achieve?
    I am trying to display a number of time series on a single graph, with the time series to display chosen by a dashboard variable

  • How are you trying to achieve it?
    I have a single mysql query like this:
    > SELECT

      db_timestamp,
      Power,
      SerialNumber
    FROM
      devicedata
    WHERE
      RIGHT(SerialNumber,4) IN (0009, 0018, 0013) 
    ORDER BY
      db_timestamp DESC
    LIMIT
      5000

which works fine.
I have set up a dashboard variable “SerialNumbersInData” from a query to get the different serialnumbers contained in the data:

SELECT DISTINCT RIGHT(SerialNumber,4) FROM devicedata WHERE SerialNumber <> “TURB0000”

I then try and use this variable in place of my comma separated list of values in above query:

    WHERE
      RIGHT(SerialNumber,4) IN $SerialNumbersInData 

But at this point I get an error saying
“db query error: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ’ ‘0009’, ‘0009’, ‘0018’ ORDER BY db_timestamp DESC LIMIT 5000’ at line 8”

I have also tried using ${SerialNumbersInData} which gets rid of the single quotes around the value, but still gives the error.

The variable is created with option for multiple values, and all value, but it doesn’t seem to matter whether I select one, several or all values, I still get the error.

If anyone has any ideas that would be great!
Thanks.