CertSafari
    Snowflake SnowPro Core Certification (COF-C03)· Lessons

    Domain 1 · Lesson 3/19

    Snowflake Session Variables, Context and Parameter Precedence

    Differentiate Snowflake object hierarchy and types

    10 min read
    5.17% of exam
    5 sources
    Published 5 Oct 2026
    Docs as of 4 Oct 2026

    What you will be able to do

    • Set, use, list and drop SQL session variables, and explain how long they last
    • Set and inspect the session's context: role, warehouse, database and schema
    • Distinguish account, session and object parameters and the levels where each can be set
    • Work out which value of a parameter wins when it is set at several levels, and confirm it with SHOW PARAMETERS

    1.SQL variables live and die with the session

    A Snowflake session keeps its own state. The simplest part of that state is a set of SQL variables that you define yourself. You create them with SET, remove them with UNSET, and list them with SHOW VARIABLES. You can also pass them in the connection string when you connect, which helps with tools where the connection string is the only thing you can customise. A variable's data type comes from whatever expression you assign to it. String and binary variables are limited to 16KB.

    When you reference a variable, prefix it with $. That's how Snowflake tells it apart from bind values and column names. You can use a variable anywhere a literal constant is allowed.

    Setting two variables in one statement and using them as literalssql
    SET (min, max)=(40, 70);
    
    SELECT $min;
    
    SELECT AVG(salary) FROM emp WHERE age BETWEEN $min AND $max;

    A variable can also hold the name of an object, such as a table. In that case $my_table_name on its own won't work in DDL. You have to wrap it in IDENTIFIER(). In a FROM clause, TABLE($my_table_name) also works.

    Variables are private to the session. Nobody can read a variable that was set in another session, and closing the session drops every variable created in it. Variable names are case-insensitive in SQL, but Snowflake stores them in uppercase. That matters for the convenience functions GETVARIABLE, SESSION_CONTEXT and SYS_CONTEXT, which take and return values as strings. GETVARIABLE('var_artist_name') returns NULL, while GETVARIABLE('VAR_ARTIST_NAME') returns the value.

    Checkpoint 1 of 6· Exam question

    A Snowflake administrator wants to create a new resource monitor to cap credit spend across every warehouse in the account. At which level of the object hierarchy must this resource monitor be created, and why?

    Checkpoint 2 of 6· Fill the gap

    my_table_name holds the string 'table1'. Which keyword lets the variable be used as the table name?

    CREATE TABLE  ? ($my_table_name) (i INTEGER);

    Sources1

    2.Session context: role, warehouse, database, schema

    Besides your own variables, every session has a context: the active role, warehouse, database and schema. Snowflake groups the commands that set these with its account and session DDL:

    - USE ROLE sets the primary role, and USE SECONDARY ROLES sets secondary roles; - USE WAREHOUSE sets the virtual warehouse for the session; - USE DATABASE and USE SCHEMA set where unqualified names resolve. The schema must be in the session's current database.

    To read the context back, Snowflake's reference points you to context functions. You call them in a plain SELECT, with no need to query any view. The SQL variables page even shows context functions being captured into variables:

    Capturing context-function results into session variablessql
    SET (current_user, current_warehouse) = ((SELECT CURRENT_USER()), (SELECT CURRENT_WAREHOUSE()));

    The organization has a context function too: any role can run CURRENT_ORGANIZATION_NAME to find out which organization the current account belongs to. Context matters because it decides what a statement does. The active role sets which privileges apply. The current database and schema decide how a short name like orders resolves to a full database.schema.object name.

    Checkpoint 3 of 6· Check yourself

    A session runs USE SCHEMA analytics; and gets an error, even though a schema named ANALYTICS exists in another database. What's the most likely cause?

    Sources23

    3.Three parameter types and where each can be set

    Variables are your own. Parameters are Snowflake's settings, and every parameter has a default value. There are three types, and each can be set at different levels.

    - Account parameters apply to the whole account. You can set them *only* at the account level, with ALTER ACCOUNT, using a role that has the necessary privilege. - Session parameters make up most parameters. Their hierarchy is Account » User » Session. An account administrator sets an account-wide default with ALTER ACCOUNT. An administrator (typically with SECURITYADMIN) or the user themselves can override it for one user with ALTER USER, and that becomes the default for every session the user starts. Any user can then override it again for the current session with ALTER SESSION. - Object parameters default to objects such as warehouses, databases, schemas and tables. Setting one at the account level makes it the default for objects created in the account. A user with the right privileges can then override it on an individual object with CREATE <object> or ALTER <object>.

    Some object parameters and the object types they can be set on
    ParameterObject typeNote
    DATA_RETENTION_TIME_IN_DAYSDatabase, Schema, TableSettable on each of the three containers
    STATEMENT_TIMEOUT_IN_SECONDSWarehouseAlso a session parameter (object and session levels)
    MAX_CONCURRENCY_LEVELWarehouseObject parameter on a warehouse
    PIPE_EXECUTION_PAUSEDSchema, PipePauses pipes at schema or pipe level
    NETWORK_POLICYUserUser-level value overrides the account-level value

    Checkpoint 4 of 6· Match them up

    Match each parameter type to the levels where it can be set

    Tap a term, then the definition that fits it.

    Sources45

    4.Precedence: the most specific level wins, and how to prove it

    Precedence follows the hierarchy: the most specific level that has a value wins. For session parameters, a session setting beats a user setting, and a user setting beats an account setting. If nothing is set at any level, the Snowflake default applies. Object parameters work the same way: a value set on the object with CREATE or ALTER overrides the account-level default. NETWORK_POLICY is a clear example: when it's set on both the account and a user, the user-level policy overrides the account-level one. STATEMENT_TIMEOUT_IN_SECONDS is worth remembering because it's both a warehouse object parameter and a session parameter.

    To see which value is actually in effect, use SHOW PARAMETERS. With no clause it shows only session parameters. Add IN <object> to see one object's parameters, or IN ACCOUNT to see all of them. If you filter by name with LIKE, it must come before IN.

    Viewing object parameters for a database and a warehousesql
    SHOW PARAMETERS IN DATABASE mydb;
    
    SHOW PARAMETERS IN WAREHOUSE mywh;

    The output has a level column that shows where the current value comes from, for example ACCOUNT. If level is empty, nobody has set the parameter and you're seeing the default. To return an account-level setting to its default, run ALTER ACCOUNT UNSET <param>.

    Checkpoint 5 of 6· Exam question

    A data engineering team needs a reusable location inside Snowflake to stage CSV files before running COPY INTO on multiple tables, without tying the location to any single table or user. Which object should they create?

    Checkpoint 6 of 6· Check yourself

    The account has STATEMENT_TIMEOUT_IN_SECONDS = 3600. A user's profile doesn't set it, but in one session they run ALTER SESSION SET STATEMENT_TIMEOUT_IN_SECONDS = 300. What does SHOW PARAMETERS LIKE 'STATEMENT_TIMEOUT%' report as the level in that session?

    Sources45

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.A variable set with SET in one worksheet session can be read by other sessions or users, or survives after the session closes.Why is that wrong?

      SQL variables are private to the session that created them and are dropped when that session closes.

      Covered in SQL variables live and die with the session

    2. 2.GETVARIABLE('my_var') finds a variable created with SET my_var = ..., because variable names are case-insensitive.Why is that wrong?

      $ references are case-insensitive, but Snowflake stores variable names in uppercase, so GETVARIABLE needs the uppercase name.

      Covered in SQL variables live and die with the session

    3. 3.Any parameter can be overridden with ALTER SESSION.Why is that wrong?

      Only session parameters cascade down to the session. Account parameters can be set only at the account level.

      Covered in Three parameter types and where each can be set

    Practise it for real

    Create, use, inspect and drop session variables, then check where a parameter's value comes from

    1. 1.Run SET (min, max)=(40, 70); and then SELECT $min;

      Why: This shows that variables are referenced with the $ prefix wherever a literal is allowed

      You should see: The SELECT returns 40

    2. 2.Run SHOW VARIABLES;

      Why: This lists every variable defined in the current session

      You should see: Two rows, named MAX and MIN (stored in uppercase), with values 70 and 40

    3. 3.Run SHOW PARAMETERS LIKE 'time%' IN ACCOUNT;

      Why: IN ACCOUNT includes account and object parameters, and LIKE must come before IN

      You should see: Parameters whose names start with TIME, with value, default and level columns

    4. 4.Run UNSET min; and then SHOW VARIABLES; again

      Why: UNSET drops a variable explicitly, without waiting for the session to end

      You should see: Only MAX remains in the list

    Stuck? Get a nudge

    If the level column is empty for a parameter, nothing has set it at any level and you're seeing Snowflake's default.

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “To distinguish them from bind values and column names, all variables must be prefixed with a $ sign.”
      ↩︎ SQL variables live and die with the session
      “When a Snowflake session is closed, all variables created during the session are dropped.”
      ↩︎ SQL variables live and die with the session
      “The size of string or binary variables is limited to 16KB.”
      ↩︎ SQL variables live and die with the session
      “To use a variable as an identifier, you must wrap it inside IDENTIFIER()”
      ↩︎ SQL variables live and die with the session
      “All of these functions accept and return session variable values as strings”
      ↩︎ SQL variables live and die with the session
      “SQL variables are private to a session.”
      ↩︎ Exam trap 1
      “In this example, the output is NULL because Snowflake stores variables with all uppercase letters.”
      ↩︎ Exam trap 2
    2. 2.
      “Using a role, warehouse, database, or schema within a session.”
      ↩︎ Session context: role, warehouse, database, schema
      “Specifies the primary role to use in the session.”
      ↩︎ Session context: role, warehouse, database, schema
      “Specifies the schema to use in the session (specified schema must be in the current database for the session).”
      ↩︎ Checkpoint
    3. 3.
      “Users with any role can execute the CURRENT_ORGANIZATION_NAME function to return the organization of the current account.”
      ↩︎ Session context: role, warehouse, database, schema
    4. 4.
      “Most parameters are session parameters, which you can set at the following levels:”
      ↩︎ Three parameter types and where each can be set
      “The values that you set for a user become the default values in any session started by that user.”
      ↩︎ Three parameter types and where each can be set
      “Users with the appropriate privileges can run the CREATE <object> or ALTER <object> commands to override object parameters for an individual object.”
      ↩︎ Three parameter types and where each can be set
      “If this parameter is set on the account and a user in the same account, the user-level network policy overrides the account-level network policy.”
      ↩︎ Precedence: the most specific level wins, and how to prove it
      “You must specify the LIKE clause before the IN clause.”
      ↩︎ Precedence: the most specific level wins, and how to prove it
      “You can only set account parameters at the account level”
      ↩︎ Exam trap 3
      “Session — Can be set for Account » User » Session”
      ↩︎ Checkpoint
      “Users can run the ALTER SESSION command to override session parameters for the current session.”
      ↩︎ Checkpoint
    5. 5.
      “Object parameters that default to objects (warehouses, databases, schemas, and tables).”
      ↩︎ Three parameter types and where each can be set
      “If the level column is empty for a parameter, the parameter is not explicitly set and the current value is the default value.”
      ↩︎ Precedence: the most specific level wins, and how to prove it
      “this date display format is only the default and can be overridden for any individual user or session.”
      ↩︎ Prediction

    Ready to test yourself?

    Practise the 21 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.