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

Set session variables for a Snowflake connection

To set session variables for a Snowflake connection:

  1. Open the Admin Portal by selecting Administration in the user menu at the top right of your screen.

  2. In the left navigation, select Connections, then select the Snowflake connection.

  3. On the connection overview, click Edit.

  4. In the Query variables section, click + Add a query variable to add one or more session variables as key-value pair mappings:

    1. For Name, enter the name of the session variable to set.

    2. 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.
  5. (Optional) Repeat step 4 to add other variables.

  6. 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_region attribute with values AMER and EU.
  • Add a session variable to the Snowflake connection with the name REGION and turn on the Set by user attribute toggle, then select the set_region attribute.

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.


Related resources