Reputation: 1340
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?
Upvotes: 1
Views: 7502
Reputation: 28626
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}'
Upvotes: 3