Warm tip: This article is reproduced from serverfault.com, please click

Use variable grafana in query with LIKE

发布于 2020-03-23 13:24:54

I'm trying to create a query in GRAFANA with LIKE using the internal variables of the tool, but it informs the value of the variable with '' and this is generating an error in the query within postgres, any suggetions?

QUERY:

select count(*) from table_name where column_name like ('%'$VARIABLE'%') LIMIT 1

OUTPUT:

pq: syntax error at or near "'VALUE_VARIABLE'"
Questioner
Luis Henrique
Viewed
0
Rizal Fahlevi 2020-12-02 16:06:21

How about this:

select count(*) from table_name where column_name like concat ('%', $VARIABLE, '%') LIMIT 1