How to get index of a substring in a grafana query

  • What Grafana version and what operating system are you using?
    8.2.2

  • What are you trying to achieve?
    I would like to parse a field in the value set to have a substring.

  • How are you trying to achieve it?
    with a sql query

  • What happened?
    i get no results back

  • What did you expect to happen?
    i expect to get a substring with just the sub string i would like to see. e.g string are “XYZ jobA modelB”. result should be “jobA”

  • Can you copy/paste the configuration(s) that you are having problems with?
    SELECT replace(substring(“jobName”,4, patindex(’%model%’, “jobName”)), ‘-’, ‘.’) AS “Job Name”,
    case when (“teamName”=‘teamA’) then AVG(“utilization”) else 0 end as “teamA”,
    case when (“tags.teamName”=‘teamB’) then AVG(“utilization”) else 0 end as “teamB”
    FROM ngcJobs
    WHERE “name” LIKE ‘XYZ%’
    AND “teamName” in (‘teamA’, 'teamB)
    GROUP BY “jobName”, “teamName”

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    no data shows when i add the patindex… into the query.

  • Did you follow any online instructions? If so, what is the URL?
    could not find a good reference doc