dungan1103
dungan1103

Reputation: 23

Using Grafana textbox panel variable in query where clause

Is there any way to use a textbox panel variable in a where clause for a state panel query?

My Dashboard has a panel variable (type Textbox) variable for current month ($CURRENT_MONTH) with a value of Feb 2021 That variable is used to update the title of a panel using $CURRENT_MONTH

I need to use that variable in the panel's query to complete the where clause logic

SELECT
  availability
FROM "mytable"
where
  dashboard='OPS Dashboard' and period=$CURRENT_MONTH

and throws the error pq: syntax error at or near "2021"

(If I replace $CURRENT_MONTH with 'Feb 2021' it works just fine)

it won't work and throws the error:

Upvotes: 1

Views: 3291

Answers (1)

Jan Garaj
Jan Garaj

Reputation: 28626

You need to pay attention to quotes:

SELECT availability 
FROM "mytable" 
WHERE dashboard='OPS Dashboard' 
  AND period='$CURRENT_MONTH'

Your homework: use Grafana query inspector and check generated SQL with and without quotes - then you should to understand a reason of quotes here.

Upvotes: 1

Related Questions