SQL builder, how to use any in?

Using on-premise grafana 11.5.1 running on rocky linux

I am trying to use the sql builder to make a where variable in(…) query.

I would expect this, or some other way of making a list of values to get me

hostname in (‘hosta’,‘hostb’) in the sql, but I have so far only gotten

hostname in (‘\‘hosta\’,\‘hostb\’’)

which is a perfectly logical thing to do, but how can I tell grafana that I have a list of possible values that I want into the sql?

I would highly discourage you from using Builder and instead use stored procedures or carve the query by hand

That kind of works, but gives a pretty funny sql

Although I guess postgres will optimize this to hostname in (‘hna1’,'hnb1). The bigger problem is that the WHERE clause in the builder is either OR or AND:

And to what you said about using hand written queries, That’s what I usually do, but when teaching my coworkers to make their own dashboards, it is easier for them to use the builder, and if I know them well, they will after a while start modifying the SQLs made by the builder.

1 Like