grafanaquestdbgrafana-variable

Why single quote escape cannot be used in QuestDB, Error: dangling expression


I'm trying to use Query Variables in Grafana, the panel query source is PostgreSQL for QuestDB.

I have added the variable without any issue, but I'm unable to use the variable in Panel query since the variable values contains the spaces (SENSOR01 ON_OFF), also I'm unable to figure-out how to add single quote escape.

Following are the scenarios I tried:

Scenario1: this indicates due to space in the Variable value, on_off considered as separate word

where sensor_name = $sensor 

db query error: pq: unexpected token: on_off

. .

Scenario2: tried to add single quotes explicitly for the variable value, but there is generic error from source DB (QuestDB)

where sensor_name = concat('''', $sensor, '''')

db query error: pq: dangling expression

When tried Scenario2 approach directly in query of Variable, getting the same error

..

Scenario3: Hard-coded the variable value with space and with single quotes, but this giving me error with first part of the variable, looks like the hard-coded single quotes not passed here!

enter image description here

Error (Scenario3):
enter image description here

Is there any way/workaround to tackle this issue?


Solution

  • Could you just add the quotes directly in the query?

    where sensor_name = '$sensor'

    I have a similar grafana panel querying a questDB database using a variable and it works for me. This is my query:

    select device_type, avg(duration_ms) as avg_duration_ms, avg(speed) as avg_speed, avg(measure1) as avg_m1, avg(measure2) as avg_m2 from ilp_test 
      WHERE
      $__timeFilter(timestamp) and device_type = '$deviceType'