Specify session variables for a Snowflake connection (Beta)
You can set session variables on a Sigma connection to Snowflake. The session variables are set for each query that Sigma runs in Snowflake. For an example using session variables with a row access policy, see Example implementation.
Requirements
- You must be assigned the Admin account type or an account type with the Manage connections permission enabled.
- You must have an existing Snowflake connection.
- (Optional) Create a user attribute to assign values of the variable to specific users or teams.
Set session variables for a Snowflake connection
To set session variables for a Snowflake connection:
-
Open the Admin Portal by selecting Administration in the user menu at the top right of your screen.
-
In the left navigation, select Connections, then select the Snowflake connection.
-
On the connection overview, click Edit.
-
In the Query variables section, click + Add a query variable to add one or more session variables as key-value pair mappings:
-
For Name, enter the name of the session variable to set.
-
Choose how to set the value of the variable:
- To set one value of the variable for all users in Sigma, enter a value.
- To set a different value of the variable for different users or teams in Sigma, turn on the Set by user attribute toggle, then select a user attribute.
-
-
(Optional) Repeat step 4 to add other variables.
-
Click Save to apply your changes.
Example implementation
For example, set session variables used in row access policies in Snowflake using GETVARIABLE syntax.
Given a row access policy definition like the following:
CREATE OR REPLACE ROW ACCESS POLICY secure_db.finance.profits AS (SALES_REGION VARCHAR) RETURNS BOOLEAN ->
GETVARIABLE('REGION') IS NULL
OR SALES_REGION=GETVARIABLE('REGION');
ALTER TABLE SECURE_DB.FINANCE.PROFITS
ADD ROW ACCESS POLICY SECURE_DB.FINANCE.PROFITS ON (SALES_REGION);Set session variables on the Snowflake connection with the following details:
- Create a user attribute in Sigma to assign values of the variable to specific users or teams. For example, a
set_regionattribute with valuesAMERandEU. - Add a session variable to the Snowflake connection with the name
REGIONand turn on the Set by user attribute toggle, then select theset_regionattribute.
When a user assigned the set_region attribute with the AMER value queries the SECURE_DB.FINANCE.PROFITS table from Sigma, they see only rows where the SALES_REGION column has a value of AMER.
Updated about 22 hours ago
