Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Variable Formatting Options to enforce quotes on each value #20011

Closed
cfconrad opened this issue Oct 25, 2019 · 4 comments
Closed

Introduce Variable Formatting Options to enforce quotes on each value #20011

cfconrad opened this issue Oct 25, 2019 · 4 comments

Comments

@cfconrad
Copy link

What would you like to be added:
I would like to have a Variable Formatting Option which force the values to be quoted.
My favorite is to have single quote.

For instance, I tried to get a string like 'test.1', 'test2' on the play site but I failed.

Why is this needed:
One of my field keys, contain a InfluxDB keyword and I would like to specify which field keys I would like to display, with an variable.

Example:
The variable ($fields) is populated with: SHOW FIELD KEYS FROM my_table
Then I would like to use it like: SELECT ${fields:singlequoted} FROM my_table WHERE ...

Problem:
My problem is, that one of the KEYS is called user@blafooo. This result with SELECT ${fields:csv} FROM ... into an DB error like:

error parsing query: found USER, expected identifier, string, number, bool at line 1, char 8

Thanks in Advance
Clemens

@cfconrad cfconrad changed the title Variable Formatting Options to enforce quotes on each value Introduce Variable Formatting Options to enforce quotes on each value Oct 25, 2019
@xiaobeiyang
Copy link
Contributor

It will be great if this feature is added.

@cfconrad
Copy link
Author

cfconrad commented Apr 8, 2020

Looks like this feature was silently implemented. From https://grafana.com/docs/grafana/latest/reference/templating/#singlequote

Singlequote

Formats single- and multi-valued variables into a comma-separated string, escapes ' in each value by \' and quotes each value with '.

servers = ['test1', 'test2']
String to interpolate: '${servers:singlequote}'
Interpolation result: "'test1','test2'"

Doublequote

Formats single- and multi-valued variables into a comma-separated string, escapes " in each value by \" and quotes each value with ".

servers = ['test1', 'test2']
String to interpolate: '${servers:doublequote}'
Interpolation result: '"test1","test2"'

@cfconrad cfconrad closed this as completed Apr 8, 2020
@cfconrad
Copy link
Author

cfconrad commented Apr 9, 2020

#21622

@Mario-Hofstaetter
Copy link

If anyone is landing here and wondering, as of Grafana v6.7.2 this is not yet working.
Meaning the docs incorrectly already mention Singlequote, Doublequote, Sqlstring,

I guess it will come with v7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants