Double single quotes

I’m trying to embed a variable in a SQL query, but I need the query as a string.

So I need, when selecting all values, instead of getting:
‘a’,‘b’,‘c’

I need two singe quotes:
‘‘a’’,‘‘bb’’,‘‘c’’

I have been looking at the formatting options, but even when I try to use the double quotes SQL/Grafana interprets them a bit different, where two single quotes together has a space between them, but the doulbequote option has them adjacent and the interpreter doesn’t like it

Compare doublequote:
image

To two single quotes (manually entered):
image

Why do you need them as such? is that how they are in the database?
How are you building the variables? statis or from db?

1 Like

that is how you write a sql query

you would do it this way

name in ('groovy','smoothie')

not

name in ("groovy","smoothie")

image

If you re-read the original post, they need the query inside of a string. There’s a variety of good reasons for needing a query in a SQL string, such as passing that to EXEC, as a stored function argument, etc.

The two-single-quotes is the way to escape a single quote within a string (which needs to be wrapped with single quotes, not double). As far as I’ve been able to figure out, there’s no way in Grafana currently to get a multi-variable’s values as a comma-separated list of double-single-quoted values.

An option like ${dashboard_variable:doublesinglequote} that returned ''val1'',''val2'',''val3'' would be immensely helpful and seems trivial to add.

4 Likes

Exactly what I was looking for!

you are a life saver

Did you find any alternative ? How did you achieve something similar
to ${dashboard_variable:doublesinglequote} ?

Ended up using a EXEC with the SQL query and adding the additional quotes as necessary

1 Like