SQL:
SELECT title, author, copyright, href, image, rating, series
FROM main
/* Long | |
WITH movie_genre AS ( | |
SELECT | |
A.title, | |
A.year, | |
B.Genre AS genre | |
FROM A | |
JOIN B ON A.imdb_id = B.imdb_id | |
), | |
genre_totals AS ( |
package sql | |
import ( | |
"context" | |
"time" | |
mysql "github.com/dolthub/go-mysql-server/sql" | |
"github.com/dolthub/go-mysql-server/sql/types" | |
) |
SQL expressions in Grafana let you perform lightweight SQL-like transformations on the results of other queries — directly within the panel. This is great for reshaping, renaming, filtering, and aggregating data without modifying the original datasource query.
SQL expressions operate on the output of another query in the same panel, referenced by its query letter (e.g., A
, B
). These expressions are parsed and executed by Grafana — not sent to an external database.
In Grafana, data coming from many sources includes sparse labels — meaning some series have label keys that others do not.
This is common in systems like Prometheus, OpenTelemetry, or SQL queries with GROUP BY.
However, traditional long formats (like time_series_long
or numeric_long
) do not preserve label sparsity correctly, leading to broken behaviors in visualization, alerts, and expressions.
package sql | |
import ( | |
"fmt" | |
mysql "github.com/dolthub/go-mysql-server/sql" | |
"github.com/dolthub/go-mysql-server/sql/types" | |
) | |
type SlothFunction struct{} |
Docs (https://grafana.com/docs/grafana/latest/administration/recorded-queries/#how-recorded-queries-work):
Recorded queries only work with backend data source plugins. Refer to Backend data source plugin for more information about backend data source plugins. You can recorded four types of queries:
- single row and column - A query that returns a single row and column.
- row count - A query that returns meaningful rows to be counted.
- expression - Any expression. To learn more about creating and using expressions, see Write expression queries.
- dataplane numeric - A query that returns dataplane numeric kind data.