Snowflake template variables
Use template variables to create dynamic, reusable dashboards with the Snowflake data source.
Before you begin
- Configure the Snowflake data source.
- Understand Grafana template variables, which allow you to create interactive dashboards with drop-down filters that dynamically update your queries.
Supported variable types
Create a query variable
To add a new Snowflake query variable, refer to Add a query variable. Use your Snowflake data source as the data source for your variable query.
Any value queried from a Snowflake table can be used as a variable. Avoid selecting too many values, as this can cause performance issues.
Note
If the variable query returns two columns, the values from the second column will be used as display values.
Use variables in queries
After creating a variable, you can use it in your Snowflake queries using variable syntax.
For more information about variables, refer to Templates and variables.
You can optionally set the interpolation format. You can also configure the default interpolation format in the data source configuration.
Variable examples
The following examples show how to use variables in different scenarios.
Single-value variables
If a variable returns a single value, use the following format.
The example below assumes you have set sqlstring as default interpolation and you have two variables:
queryTypeSinglewith valueSELECTlimitwith value2
Query with variables:
SELECT query_type FROM account_usage.query_history WHERE query_type = ${queryTypeSingle} LIMIT ${limit:raw}Interpolated query:
SELECT query_type FROM account_usage.query_history WHERE query_type = 'SELECT' LIMIT 10Note
The default variable interpolation type
sqlstringwas introduced in version 1.2. From this version, you can set the default interpolation type tosqlstring.
Prior to version 1.2 of the plugin, or if you use none as the default interpolation type, write the same query as follows:
SELECT query_type FROM account_usage.query_history WHERE query_type = '${queryTypeSingle}' LIMIT ${limit:raw}Multi-value variables with sqlstring interpolation
When consuming a variable that returns multiple options, use the following method.
The example below assumes you have set sqlstring as default interpolation and you have two variables:
queryTypeMultiwith valuesCREATE,SELECTlimitwith value2
Query with variables:
SELECT query_type FROM account_usage.query_history WHERE query_type IN (${queryTypeMulti}) LIMIT ${limit:raw}Interpolated query:
SELECT query_type FROM account_usage.query_history WHERE query_type IN ('CREATE','SELECT') LIMIT 10Multi-value variables with regex
To use a variable that has multiple values with pattern matching, use the
regex modifier option and the regexp Snowflake function.
Use ${variable:regex} syntax:
Query with variables:
SELECT *
FROM account_usage.query_history
WHERE query_type REGEXP '${queryType:regex}'Interpolated query:
SELECT *
FROM account_usage.query_history
WHERE query_type REGEXP '(DESCRIBE|CREATE_USER|DROP|TRUNCATE_TABLE|ALTER)'Configure default interpolation
You can set a default interpolation format in the data source configuration:
- Navigate to Connections > Data sources.
- Select your Snowflake data source.
- In the Default Interpolation field, select your preferred format (for example,
sqlstring). - Click Save & test.
When set, all variables without an explicit format modifier will use this default interpolation.



