1

How I can use variable in sql query at Grafana? I have variable robot but I do not know how I can use it in sql query. My query:

SELECT 
  datetime AS "time",
  api_robot.name AS "robot name",
  api_task.name AS "task name",
  api_status.name AS "task status"
FROM api_robotlog, api_robot, api_status, api_task
WHERE 
    -- api_robot.name = {$robot}
   api_robotlog.robot_id = api_robot.id
  AND api_robotlog.task_id = api_task.id

I try add some clauses at WHERE like: api_robot.name = {$robot} api_robot.name = ${robot} But when I use it, I do not receive any data. Any idea? enter image description here

1 Answer 1

4

Use Grafana variable syntax, which will generate correct SQL condition, e.g.:

api_robot.name = $robot

You may also need advance variable format options, e.g.:

api_robot.name = '${robot:raw}'
Sign up to request clarification or add additional context in comments.

1 Comment

thank You! 2nd case (with {} and '') working!

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.