Snowflake SQL Tutorial 172 - One Parameter, Three Different Answers. ALTER SESSION Explained

Snowflake SQL · Episode 172

In this post we are going to cover ALTER SESSION and parameters in Snowflake.

A parameter in Snowflake has two things worth looking at. It has a value, and it has a level. The level is who set it: the account, a warehouse, a user, your session, or nobody at all. Almost everything that is confusing about ALTER SESSION turns out to be a question about that second column.

We will start with how many parameters a session has and build it up step by step. Along the way we will ask one parameter the same question three ways and get three different answers, and all three will be true.

Every query below was run on a real Snowflake account, and every result you see is the output it gave back.

Episode 172 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.

Let's create a table to work with

Some of the parameters in this post change how dates and times come out, so we need a few fixed dates to watch. The script below makes a small table with three of them.

Sample data
-- Sample data for this post.
-- Three fixed dates and timestamps, so we can watch what an output format
-- does and does not change.
USE DATABASE DEMO_DB;

CREATE OR REPLACE SCHEMA DEMO_DB.SESS_T172
    COMMENT = 'episode 172 - session parameters, dropped at the end';

USE SCHEMA DEMO_DB.SESS_T172;

CREATE OR REPLACE TABLE DEMO_DB.SESS_T172.WHEN_T172 (
    LABEL      VARCHAR(20),
    THE_DATE   DATE,
    THE_STAMP  TIMESTAMP_NTZ
);

INSERT INTO DEMO_DB.SESS_T172.WHEN_T172 (LABEL, THE_DATE, THE_STAMP)
VALUES ('first',  '2026-01-31', '2026-01-31 08:05:00'),
       ('second', '2026-06-15', '2026-06-15 14:30:45'),
       ('third',  '2026-11-02', '2026-11-02 23:59:59');

Let's read it back, with everything still at its default.

Query
SELECT * FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_DATE;
Result3 rows · 3 columns
LABELTHE_DATETHE_STAMP
first2026-01-312026-01-31 08:05:00
second2026-06-152026-06-15 14:30:45
third2026-11-022026-11-02 23:59:59

Three rows, a DATE column and a TIMESTAMP_NTZ column. And here is where the session is pointing while we do all this.

Query
SELECT CURRENT_DATABASE()  AS THE_DATABASE,
       CURRENT_SCHEMA()    AS THE_SCHEMA,
       CURRENT_WAREHOUSE() AS THE_WAREHOUSE,
       CURRENT_ROLE()      AS THE_ROLE;
Result1 row · 4 columns
THE_DATABASETHE_SCHEMATHE_WAREHOUSETHE_ROLE
DEMO_DBPUBLICCOMPUTE_WHACCOUNTADMIN

Let's start with how many parameters a session has

SHOW PARAMETERS IN SESSION lists them all.

Result161 rows · 6 columns · showing first 4 · scroll →
The first four rows of it, alphabetically.
keyvaluedefaultleveldescriptiontype
ABORT_DETACHED_QUERYfalsefalseIf true, Snowflake will automatically abort queries when it detects that the client has disappeared.BOOLEAN
ACTIVE_PYTHON_PROFILERWhich profiler is currently active to analyze user code for Python sprocs. Possible values are "LINE" and "MEMORY".STRING
AI_SQL_EMBED_SIMILARITY_ERROR_HANDLING_USE_FAIL_ON_ERRORtruetrueWhen enabled, old fail on error behavior will be observed for AI_EMBED and AI_SIMILARITYBOOLEAN
AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERRORfalsefalseWhen enabled, old fail on error behavior will be observedBOOLEAN
Query
SELECT COUNT(*) AS PARAMETERS_IN_A_SESSION
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
PARAMETERS_IN_A_SESSION
161

A hundred and sixty one parameters. That is a lot of things you could be wrong about.

Look at the columns. There is the key, the current value, the default, the level, a description and the type. Six columns, and the one everybody skips is the fourth.

Now let's try a bare SHOW PARAMETERS with no IN clause at all.

Query
SHOW PARAMETERS;
Query
SELECT COUNT(*) AS PARAMETERS_A_BARE_SHOW_RETURNS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
PARAMETERS_A_BARE_SHOW_RETURNS
161

The same number. So the session is the default scope, which is one less thing to remember.

Now the column that matters

On most of those rows the level column is blank. Blank means nobody set it here, so the value you are looking at is the default.

Let's count how many carry a level at all, on a session where we have not touched anything yet.

Query
SELECT COUNT(*) AS PARAMETERS_SOMEBODY_SET
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE NULLIF(TRIM("level"), '') IS NOT NULL;
Result1 row · 1 column
PARAMETERS_SOMEBODY_SET
8

Eight. And not one of them is mine. Here they are.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE NULLIF(TRIM("level"), '') IS NOT NULL
 ORDER BY "key";
Result8 rows · 4 columns
keyvaluedefaultlevel
CLIENT_PREFETCH_THREADS44SESSION
ENABLE_USE_STABLE_PATHtruefalseSYSTEM
ODBC_QUERY_RESULT_FORMATARROWARROWSYSTEM
PYTHON_SNOWPARK_ELIMINATE_NUMERIC_SQL_VALUE_CAST_ENABLEDtruefalseSYSTEM
PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSIONtruetrueSYSTEM
PYTHON_SNOWPARK_USE_CTE_OPTIMIZATION_VERSION999.999.9991.31.1SYSTEM
SNOWPARK_USE_SCOPED_TEMP_OBJECTSfalsefalseSYSTEM
WORKSHEETS_MIGRATEDtruefalseUSER

One of them says SESSION, and that is the Python connector setting its prefetch threads when it connected. Six of them say SYSTEM, which is Snowflake itself. One says USER.

All eight of those were already there before my first statement ran. So the level column is already telling you things on a session you have only just opened.

Blank is an empty string, not a NULL

Those blank level cells are not NULL. SHOW reports a missing value as an empty string, and this page marks an empty string as an empty cell rather than printing a word into it. That is also why the query that counts them uses NULLIF(TRIM("level"), '') rather than IS NOT NULL: a test for NULL would have matched all 161 rows.

Let's set one and watch the level change

The timezone is the parameter everybody meets first. Let's look at it before touching it.

Query
SHOW PARAMETERS LIKE 'TIMEZONE' IN SESSION;
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
TIMEZONEAmerica/Los_AngelesAmerica/Los_Angeles

The value and the default are the same, and the level is blank. Nobody set it. That is simply where this account was made. And here is what the clock says under it.

Query
SELECT CURRENT_TIMESTAMP()          AS WHAT_TIME_IT_IS,
       CURRENT_TIMESTAMP()::DATE    AS WHAT_DAY_IT_IS;
Result1 row · 2 columns
WHAT_TIME_IT_ISWHAT_DAY_IT_IS
2026-10-08 05:02:02.165000-07:002026-10-08

Now let's move the session to another timezone.

Query
ALTER SESSION SET TIMEZONE = 'Asia/Karachi';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT CURRENT_TIMESTAMP()          AS WHAT_TIME_IT_IS,
       CURRENT_TIMESTAMP()::DATE    AS WHAT_DAY_IT_IS;
Result1 row · 2 columns
WHAT_TIME_IT_ISWHAT_DAY_IT_IS
2026-10-08 17:02:02.445000+05:002026-10-08

A different time, and in this case a different wall-clock hour on the same date. Nothing moved. That is one instant, rendered somewhere else.

Here is the same instant in three zones at once, to make that concrete.

Query
SELECT CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP())            AS IN_UTC,
       CONVERT_TIMEZONE('America/Los_Angeles', CURRENT_TIMESTAMP()) AS IN_LOS_ANGELES,
       CONVERT_TIMEZONE('Asia/Karachi', CURRENT_TIMESTAMP())   AS IN_KARACHI;
Result1 row · 3 columns
IN_UTCIN_LOS_ANGELESIN_KARACHI
2026-10-08 12:02:02.582000+00:002026-10-08 05:02:02.582000-07:002026-10-08 17:02:02.582000+05:00

Three renderings, one moment. Look at the offsets: minus seven, plus five, and none. That is the whole of what a timezone does.

And the parameter now has a level on it.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
TIMEZONEAsia/KarachiAmerica/Los_AngelesSESSION

The value changed, the default did not, and the level says SESSION. That is us.

A test of mine that proved nothing

WEEK_START decides which day a week begins on. Let's look at it first.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
WEEK_START00

Value nought, default nought, blank level. Now here is a fixed date under that setting.

Query
SELECT '2026-03-04'::DATE                        AS THE_DATE,
       DAYOFWEEK('2026-03-04'::DATE)             AS DAY_OF_WEEK,
       DAYOFWEEKISO('2026-03-04'::DATE)          AS DAY_OF_WEEK_ISO,
       WEEKOFYEAR('2026-03-04'::DATE)            AS WEEK_OF_YEAR,
       DATE_TRUNC('week', '2026-03-04'::DATE)    AS START_OF_ITS_WEEK;
Result1 row · 5 columns
THE_DATEDAY_OF_WEEKDAY_OF_WEEK_ISOWEEK_OF_YEARSTART_OF_ITS_WEEK
2026-03-0433102026-03-02

Day of week three, week of year ten, and the week it belongs to starts on the second of March.

Now let's make the week start on Monday instead.

Query
ALTER SESSION SET WEEK_START = 1;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
WEEK_START10SESSION

The parameter took, and the level says SESSION. So let's run the identical date again.

Query
SELECT '2026-03-04'::DATE                        AS THE_DATE,
       DAYOFWEEK('2026-03-04'::DATE)             AS DAY_OF_WEEK,
       DAYOFWEEKISO('2026-03-04'::DATE)          AS DAY_OF_WEEK_ISO,
       WEEKOFYEAR('2026-03-04'::DATE)            AS WEEK_OF_YEAR,
       DATE_TRUNC('week', '2026-03-04'::DATE)    AS START_OF_ITS_WEEK;
Result1 row · 5 columns
THE_DATEDAY_OF_WEEKDAY_OF_WEEK_ISOWEEK_OF_YEARSTART_OF_ITS_WEEK
2026-03-0433102026-03-02

Identical. Every column is the same as before. The parameter changed and the answer did not move at all.

And that is my fault, not Snowflake's. The date I picked, the fourth of March 2026, is a Wednesday, which the DAY_OF_WEEK_ISO column in that grid tells us. A Wednesday falls in the middle of the week whichever end you start counting from, and the week containing it starts on the same day either way.

Why this is still here

A test that cannot fail proves nothing, and this one could not fail. If you want to see WEEK_START do something, pick a Sunday: that is the day the two settings disagree about. This is on the page rather than quietly cut, because picking the wrong sample date is the most ordinary way there is to convince yourself a setting does nothing.

Now the output formats: looks versus is

DATE_OUTPUT_FORMAT decides how a DATE is written out. Let's look at it first.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
DATE_OUTPUT_FORMATYYYY-MM-DDYYYY-MM-DD

Year, month, day, with dashes, and a blank level. Let's change it to day, month name, year.

Query
ALTER SESSION SET DATE_OUTPUT_FORMAT = 'DD-MON-YYYY';
Result1 row · 1 column
status
Statement executed successfully.

And now the same three rows again.

Query
SELECT * FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_DATE;
Result3 rows · 3 columns
LABELTHE_DATETHE_STAMP
first2026-01-312026-01-31 08:05:00
second2026-06-152026-06-15 14:30:45
third2026-11-022026-11-02 23:59:59

That grid is identical, cell for cell, to the one we read at the top of this post, and it is worth saying why rather than pretending otherwise. Every result on this page was captured through the Python connector, which fetches a DATE as a date value and writes it out itself. A session output format never reaches it. In a Snowflake worksheet the server does the writing out, and that is where this parameter shows.

What the capture does show is the part that matters more, and it shows it properly.

Query
SELECT LABEL,
       THE_DATE,
       YEAR(THE_DATE)   AS THE_YEAR,
       MONTH(THE_DATE)  AS THE_MONTH,
       DAY(THE_DATE)    AS THE_DAY
  FROM DEMO_DB.SESS_T172.WHEN_T172
 ORDER BY THE_DATE;
Result3 rows · 5 columns
LABELTHE_DATETHE_YEARTHE_MONTHTHE_DAY
first2026-01-312026131
second2026-06-152026615
third2026-11-022026112

The year, the month and the day of each stored value are exactly what we inserted. Nothing was updated. An output format changes what comes out of a column. It does not change what is in it.

The timestamp format behaves the same way, and so does its grid.

Query
ALTER SESSION SET TIMESTAMP_OUTPUT_FORMAT = 'YYYY-MM-DD"T"HH24:MI:SS';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT LABEL, THE_STAMP FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_STAMP;
Result3 rows · 2 columns
LABELTHE_STAMP
first2026-01-31 08:05:00
second2026-06-15 14:30:45
third2026-11-02 23:59:59
Rendering is not storage

This is a good thing to be caught by once. If an output format could change the stored value, every report would be a migration. It cannot, and the YEAR/MONTH/DAY grid above is the proof rather than the promise.

Now let's tag our queries

QUERY_TAG is a string you can hang on a session, and it ends up on every query that session runs. Let's see it empty first.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
QUERY_TAG

An empty value, an empty default and a blank level. Now let's set one and run something.

Query
ALTER SESSION SET QUERY_TAG = 'episode-172-tagged';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT COUNT(*) AS ROWS_IN_MY_TABLE
  FROM DEMO_DB.SESS_T172.WHEN_T172;
Result1 row · 1 column
ROWS_IN_MY_TABLE
3

Now let's go looking for that tag in the query history.

Query
SELECT QUERY_TAG, QUERY_TYPE, EXECUTION_STATUS, ROLE_NAME
  FROM TABLE(DEMO_DB.INFORMATION_SCHEMA.QUERY_HISTORY(RESULT_LIMIT => 10))
 WHERE QUERY_TAG = 'episode-172-tagged'
 ORDER BY START_TIME DESC;
Result2 rows · 4 columns
QUERY_TAGQUERY_TYPEEXECUTION_STATUSROLE_NAME
episode-172-taggedSELECTRUNNINGACCOUNTADMIN
episode-172-taggedSELECTSUCCESSACCOUNTADMIN

Two rows carrying our tag, and one of them is still RUNNING, because it is the query asking the question. Let's widen the window and count.

Query
SELECT COUNT(*) AS QUERIES_CARRYING_MY_TAG
  FROM TABLE(DEMO_DB.INFORMATION_SCHEMA.QUERY_HISTORY(RESULT_LIMIT => 200))
 WHERE QUERY_TAG = 'episode-172-tagged';
Result1 row · 1 column
QUERIES_CARRYING_MY_TAG
3

Three at that moment. Now let's change the tag in the middle of the session and run something else.

Query
ALTER SESSION SET QUERY_TAG = 'episode-172-retagged';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT COUNT(*) AS ROWS_AGAIN
  FROM DEMO_DB.SESS_T172.WHEN_T172;
Result1 row · 1 column
ROWS_AGAIN
3
Query
SELECT QUERY_TAG, COUNT(*) AS HOW_MANY
  FROM TABLE(DEMO_DB.INFORMATION_SCHEMA.QUERY_HISTORY(RESULT_LIMIT => 200))
 WHERE QUERY_TAG LIKE 'episode-172%'
 GROUP BY QUERY_TAG
 ORDER BY QUERY_TAG;
Result2 rows · 2 columns
QUERY_TAGHOW_MANY
episode-172-retagged2
episode-172-tagged5

Two tags, two counts, one session. The first tag has gone from three to five, because the statements we ran in between were still carrying it. The tag applies from the moment you set it onwards, and nothing retags what already ran.

Now the one to take away: one parameter, three answers

This is the part I want you to remember. We are going to ask one parameter the same question three ways.

First we need a warehouse of our own to put a setting on. It never runs anything.

Setup
-- A warehouse of our own that never runs anything. We only want to
-- read a parameter off it.
CREATE OR REPLACE WAREHOUSE WH_T172
    WAREHOUSE_SIZE = XSMALL
    AUTO_SUSPEND = 60
    INITIALLY_SUSPENDED = TRUE
    COMMENT = 'episode 172 - read in the catalog, never used';

Creating a warehouse points the session at it, so let's put the session straight back on the one we were using and check that it worked.

Query
USE WAREHOUSE COMPUTE_WH;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT CURRENT_WAREHOUSE() AS THE_WAREHOUSE;
Result1 row · 1 column
THE_WAREHOUSE
COMPUTE_WH

Now let's put a statement timeout on our own warehouse.

Query
ALTER WAREHOUSE WH_T172 SET STATEMENT_TIMEOUT_IN_SECONDS = 1200;
Result1 row · 1 column
status
Statement executed successfully.
Query
SHOW PARAMETERS LIKE 'STATEMENT\_TIMEOUT\_IN\_SECONDS'
    IN WAREHOUSE WH_T172;
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
STATEMENT_TIMEOUT_IN_SECONDS1200172800WAREHOUSE

Twelve hundred, and the level says WAREHOUSE. Now let's set the same parameter name on the session.

Query
ALTER SESSION SET STATEMENT_TIMEOUT_IN_SECONDS = 300;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
STATEMENT_TIMEOUT_IN_SECONDS300172800SESSION

Three hundred, level SESSION. Let's ask the warehouse again, to be sure it did not move.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
STATEMENT_TIMEOUT_IN_SECONDS1200172800WAREHOUSE

Still twelve hundred. And now the third way of asking: the warehouse the session is actually running on, which we never touched.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
STATEMENT_TIMEOUT_IN_SECONDS172800172800

A hundred and seventy two thousand eight hundred, with a blank level. That is the default, which is two days.

One parameter name. Three statements. Three different answers, all at the same moment, and nothing about that is inconsistent. The question is always on what.

Why the level column is the useful one

A value with no level beside it is just the default looking like a decision. If somebody tells you the statement timeout on your account is two days, ask them which object they read it off, because the answer differs by object and the level column is the only thing that tells you whether anybody chose it.

Let's set three in one statement

One ALTER SESSION SET can take several parameters, separated by commas.

Query
ALTER SESSION SET
    AUTOCOMMIT                   = TRUE,
    ERROR_ON_NONDETERMINISTIC_UPDATE = TRUE,
    LOCK_TIMEOUT                 = 600;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "key" IN ('AUTOCOMMIT','ERROR_ON_NONDETERMINISTIC_UPDATE','LOCK_TIMEOUT')
 ORDER BY "key";
Result3 rows · 4 columns
keyvaluedefaultlevel
AUTOCOMMITtruetrueSESSION
ERROR_ON_NONDETERMINISTIC_UPDATEtruefalseSESSION
LOCK_TIMEOUT60043200SESSION

All three took and all three say SESSION. Now look at the first row carefully.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
AUTOCOMMITtruetrueSESSION

Value true, default true, level SESSION. AUTOCOMMIT was already true. We set it to true. Nothing changed, and the level still records us.

So the level means you set it. It does not mean you changed it. Those are two different facts, and nothing in that row tells you which one happened.

Now the refusals, and one of them lies about why

Eight statements in this post are refused, and they are not all the same kind of no. First, a parameter I expected to be account-only.

Query
ALTER SESSION SET MIN_DATA_RETENTION_TIME_IN_DAYS = 1;
Query failed — Snowflake returned an error
001006 (22023): SQL compilation error:
invalid parameter 'MIN_DATA_RETENTION_TIME_IN_DAYS'

001006, invalid parameter. Fair enough. That one is an account setting and a session is not an account.

Now the same name without the MIN_ on the front. That is a real parameter, and it is settable on every database and every table in Snowflake.

Query
ALTER SESSION SET DATA_RETENTION_TIME_IN_DAYS = 2;
Query failed — Snowflake returned an error
001006 (22023): SQL compilation error:
invalid parameter 'DATA_RETENTION_TIME_IN_DAYS'

001006, invalid parameter. The identical message. Now a name I invented, which does not exist anywhere in Snowflake.

Query
ALTER SESSION SET NO_SUCH_PARAMETER_T172 = 1;
Query failed — Snowflake returned an error
001006 (22023): SQL compilation error:
invalid parameter 'NO_SUCH_PARAMETER_T172'

001006, invalid parameter. Word for word the same again.

So a real parameter used in the wrong place and a name that was never real give you the same sentence. That is the same trap Episode 170 found with 002003: one code doing duty for more than one problem, and no way to tell from the message which one you have.

Now three bad values. A word where a number belongs.

Query
ALTER SESSION SET WEEK_START = 'Monday';
Query failed — Snowflake returned an error
001008 (22023): SQL compilation error:
invalid value ['Monday'] for parameter 'WEEK_START'

001008, invalid value, and notice it quotes the value back. A number out of range next.

Query
ALTER SESSION SET WEEK_START = 9;
Query failed — Snowflake returned an error
001008 (22023): SQL compilation error:
invalid value [9] for parameter 'WEEK_START'

The same code. And a timezone that does not exist.

Query
ALTER SESSION SET TIMEZONE = 'Mars/Olympus_Mons';
Query failed — Snowflake returned an error
001008 (22023): SQL compilation error:
invalid value [Mars/Olympus_Mons] for parameter 'TIMEZONE'

001008 again. And here is the question worth asking after a failed SET: did it leave the parameter in a mess?

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
TIMEZONEAsia/KarachiAmerica/Los_AngelesSESSION

Intact. The value we set earlier is still there. A refused SET changes nothing at all.

And last, the two syntax errors.

Query
ALTER SESSION SET;
Query failed — Snowflake returned an error
001003 (42000): SQL compilation error:
syntax error line 1 at position 17 unexpected '<EOF>'.
Query
ALTER SESSION UNSET;
Query failed — Snowflake returned an error
001003 (42000): SQL compilation error:
syntax error line 1 at position 19 unexpected '<EOF>'.

001003 both times, unexpected end of file. So three codes across those eight statements: 001006 for a name it will not accept here, 001008 for a value it will not accept, and 001003 for a statement that is not a statement.

Let's put some of them back with UNSET

UNSET takes the level off and the value goes back to the default with it. Let's unset two of the three we set together, and leave the third so there is something to compare against.

Query
ALTER SESSION UNSET AUTOCOMMIT, LOCK_TIMEOUT;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "key" IN ('AUTOCOMMIT','ERROR_ON_NONDETERMINISTIC_UPDATE','LOCK_TIMEOUT')
 ORDER BY "key";
Result3 rows · 4 columns
keyvaluedefaultlevel
AUTOCOMMITtruetrue
ERROR_ON_NONDETERMINISTIC_UPDATEtruefalseSESSION
LOCK_TIMEOUT4320043200

Two blank levels, one still SESSION. And look at LOCK_TIMEOUT: its value has gone back to the default as well, not stayed where we put it.

Now what happens if we unset something nobody ever set?

Query
ALTER SESSION UNSET JSON_INDENT;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
JSON_INDENT22

No error at all. It simply succeeds, and the parameter is exactly as it was. So UNSET is safe to run blind, which matters when you are cleaning up after yourself.

One last thing: a clean-up check that found something

This post is the only place in the course that runs ALTER SESSION, and a session setting outlives the statement that made it. So everything gets put back.

Clean-up
-- Everything this post set, put back.
ALTER SESSION UNSET TIMEZONE;
ALTER SESSION UNSET WEEK_START;
ALTER SESSION UNSET DATE_OUTPUT_FORMAT, TIMESTAMP_OUTPUT_FORMAT;
ALTER SESSION UNSET QUERY_TAG;
ALTER SESSION UNSET STATEMENT_TIMEOUT_IN_SECONDS;
ALTER SESSION UNSET ERROR_ON_NONDETERMINISTIC_UPDATE;

Let's look at all nine parameters this post touched, in one grid.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "key" IN ('TIMEZONE','WEEK_START','DATE_OUTPUT_FORMAT',
                 'TIMESTAMP_OUTPUT_FORMAT','QUERY_TAG',
                 'STATEMENT_TIMEOUT_IN_SECONDS',
                 'ERROR_ON_NONDETERMINISTIC_UPDATE','AUTOCOMMIT','LOCK_TIMEOUT')
 ORDER BY "key";
Result9 rows · 4 columns
keyvaluedefaultlevel
AUTOCOMMITtruetrue
DATE_OUTPUT_FORMATYYYY-MM-DDYYYY-MM-DD
ERROR_ON_NONDETERMINISTIC_UPDATEfalsefalse
LOCK_TIMEOUT4320043200
QUERY_TAG
STATEMENT_TIMEOUT_IN_SECONDS172800172800
TIMESTAMP_OUTPUT_FORMATYYYY-MM-DD HH24:MI:SS.FF3 TZHTZMYYYY-MM-DD HH24:MI:SS.FF3 TZHTZM
TIMEZONEAmerica/Los_AngelesAmerica/Los_Angeles
WEEK_START00

Every level blank again, and every value back where it started. Now the check: how many parameters are still set at session level?

Query
SELECT COUNT(*) AS PARAMETERS_STILL_SET
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE UPPER(TRIM("level")) = 'SESSION';
Result1 row · 1 column
PARAMETERS_STILL_SET
1

One. And it is not mine. It is the prefetch threads the Python connector set before my first statement ran, which we saw in the list of eight right at the start. The check was right to flag something and wrong about whose it was.

Let's confirm the time and the dates render as they did at the beginning.

Query
SELECT CURRENT_TIMESTAMP()                     AS WHAT_TIME_IT_IS,
       DAYOFWEEK('2026-03-04'::DATE)           AS DAY_OF_WEEK,
       DATE_TRUNC('week', '2026-03-04'::DATE)  AS START_OF_ITS_WEEK;
Result1 row · 3 columns
WHAT_TIME_IT_ISDAY_OF_WEEKSTART_OF_ITS_WEEK
2026-10-08 05:02:36.402000-07:0032026-03-02
Query
SELECT * FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_DATE;
Result3 rows · 3 columns
LABELTHE_DATETHE_STAMP
first2026-01-312026-01-31 08:05:00
second2026-06-152026-06-15 14:30:45
third2026-11-022026-11-02 23:59:59

Back to the offset we started on, and the same week start as the first time we asked. Now the objects.

Clean-up
-- And the objects.
DROP WAREHOUSE IF EXISTS WH_T172;
DROP TABLE IF EXISTS DEMO_DB.SESS_T172.WHEN_T172;
USE SCHEMA DEMO_DB.PUBLIC;
DROP SCHEMA IF EXISTS DEMO_DB.SESS_T172;
Query
SHOW WAREHOUSES;
Query
SELECT "name", "state", "size", "is_current"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 ORDER BY "name";
Result3 rows · 4 columns
namestatesizeis_current
COMPUTE_WHSTARTEDX-SmallY
SNOWFLAKE_LEARNING_WHSUSPENDEDX-SmallN
SYSTEM$STREAMLIT_NOTEBOOK_WHSUSPENDEDX-SmallN
Query
SELECT COUNT(*) AS MY_WAREHOUSES_LEFT
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
MY_WAREHOUSES_LEFT
0
Query
SELECT COUNT(*) AS MY_SCHEMAS_LEFT
  FROM DEMO_DB.INFORMATION_SCHEMA.SCHEMATA
 WHERE SCHEMA_NAME = 'SESS_T172';
Result1 row · 1 column
MY_SCHEMAS_LEFT
0

Three warehouses, none of them ours, and nothing of ours left in the database either.

Query
SELECT CURRENT_ROLE() AS THE_ROLE, CURRENT_SECONDARY_ROLES() AS THE_SECONDARY_ROLES;
Result1 row · 2 columns
THE_ROLETHE_SECONDARY_ROLES
ACCOUNTADMIN{"roles":"ORGADMIN","value":"ALL"}

Key points

  • A parameter has a value and a level, and the level is who set it. A blank level means nobody did, so you are looking at the default.
  • SHOW PARAMETERS IN SESSION returned 161 rows, and a bare SHOW PARAMETERS returned the same 161. The session is the default scope.
  • Eight of those 161 already carried a level before the first statement ran: one set by the connector, six by the system, one on the user.
  • The same parameter name gave three different answers at one moment: 1200 at WAREHOUSE level, 300 at SESSION level, and the default on a warehouse nobody had touched. The question is always “on what”.
  • Setting a parameter to the value it already had still records a level of SESSION. The level says you set it, not that you changed it.
  • TIMEZONE and the output formats change how a value is rendered. The stored year, month and day never moved.
  • QUERY_TAG applies from the moment you set it onwards, and retagging mid-session does not retag what already ran.
  • 001006 is the answer for a real parameter in the wrong place and for a name that does not exist. 001008 is a bad value, and 001003 is a SET or UNSET with nothing after it.
  • A refused SET leaves the parameter exactly as it was.
  • UNSET removes the level and restores the default value, and unsetting something that was never set is not an error.
  • Check your clean-up, and read what the check tells you. Ours found one parameter still set at session level, and it was not ours.
Next in this series

In the next post, the last one in this series, we look at replication: what it takes to copy a database to another account, what happens when you only have one account, and what a single account can still recover on its own.

Every query and every result grid on this page was captured from a live Snowflake account (version 10.36.101) running the demo script for this episode. That script was run last in its batch on purpose, because it is the only file in this course allowed to run ALTER SESSION and a session setting leaks into whatever runs after it. It cleans up after itself and proves it above. The output-format grids are identical because these results came back through a driver that renders dates itself, which the post says where it shows them. Grids that identify the account, its session or its user are deliberately left off the page. Nothing is timed and no performance claims are made anywhere in this series. Behaviour follows the Snowflake parameters documentation.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.