Variable not passing to MySQL query

I’ve read, and followed examples. But I’ve not been able to get a panel to acknowledge a variable sent through the URL to an MySQL query.

First, I have a bar graph with datalinks:${__data.fields.tag}

I have tried two variable types. “Custom” and “Constant”. Currently, set to Custom:

Clicking the tooltip on the barchart generates the URL:

I can see the variable has been sent.
I have another panel with a MySQL query:
select abunchofthing where tag = ‘$clantag’;

But ‘clantag’ is never populated in the panel. it’s always blank.
What am I missing?

You have not provided any data to that variable that I can see

I’m not sure what you mean - unless you mean the definition of the variable. in which case, sure.
Is the variable supposed to contain all possible values of what I pass from the data link?

I tried what this guy did:

If I make this variable a “constant” and supply a default value only the default value gets passed.

So, I guess I am not sure what you mean, or how the data link is supposed to tie to the variable.

1 Like

Yes it has to have some value otherwise it will be blank

The value can come from static stuff you type in, or from a db query or key value pair you add manually etc

I would encourage you to read the documentation first too

I’ve read the following documents:

It was not clear to me in any of these that a “variable” must be pre-defined in order to use it.

I made the change to make my variable a “query” type of all the possible values, but the data is still not showing up in the panel.

The URL passed from the data link is now:

When I inspect the panel query, it still shows blank:

I thought that would be it, and I feel closer but still not getting the desired results.
Thank you for the help.

1 Like

Check this out

You have it in quotes and since there is no variable named ‘$clantaf’ (with single quotes), it defaults to blank. Try removing the single quotes and see if it works.

That really doesn’t make any sense. The variable is encapsulated in quotes so MySQL treats it as a string. There is no variable named ‘$clantag’ as you’ve stated. If there was I would reference it was $‘$clantag’ The ‘$’ indicates it’s a variable, not the double quotes. Removing them only breaks the SQL statement further:

The example you referenced is doing the same thing with strings:

SELECT hostname FROM my_host  WHERE hostname LIKE '$__searchFilter'

It also states:
" From Grafana 4.7.0, template variable values are only quoted when the template variable is a multi-value ."

This is not a multi-value variable, so quoting it is relevant.

I am continuing to read and try and figure out why this doesn’t work.

I have solved this.

First and fore most: The variable does not have to contain a pre-populated list of potential values. That is wrong information.

Second, the issue is that the data had a “#” in it, which needed to be URL encoded. I solved this by changing the datalink to this have this on the end:

1 Like