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
Ad hoc filters aren’t supported by the Snowflake data source. Grafana-native variable types that don’t depend on the data source, such as Constant, Text box, and Interval, work as usual.
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, because doing so can cause performance issues.
Note
If the variable query returns two columns, the first column is used as the variable value and the second column is used as the display text. If the query returns a single column, that column is used as both the value and the display text.
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 snowflake.account_usage.query_history WHERE query_type = ${queryTypeSingle} LIMIT ${limit:raw}Interpolated query:
SELECT query_type FROM snowflake.account_usage.query_history WHERE query_type = 'SELECT' LIMIT 2Note
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 snowflake.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 snowflake.account_usage.query_history WHERE query_type IN (${queryTypeMulti}) LIMIT ${limit:raw}Interpolated query:
SELECT query_type FROM snowflake.account_usage.query_history WHERE query_type IN ('CREATE','SELECT') LIMIT 2Multi-value variables with regular expressions
To use a variable that has multiple values with pattern matching, use the
regular expression format option and the regexp Snowflake function.
Use ${variable:regex} syntax:
Query with variables:
SELECT *
FROM snowflake.account_usage.query_history
WHERE query_type REGEXP '${queryType:regex}'Interpolated query:
SELECT *
FROM snowflake.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 Customization section, in the Variable Interpolation Format field, select your preferred format (for example, Sql String, which is displayed as two words in the drop-down).
- Click Save & test.
When set, all variables without an explicit format modifier use this default interpolation.


