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
- Let's start with how many parameters a session has
- Now the column that matters
- Let's set one and watch the level change
- A test of mine that proved nothing
- Now the output formats: looks versus is
- Now let's tag our queries
- Now the one to take away: one parameter, three answers
- Let's set three in one statement
- Now the refusals, and one of them lies about why
- Let's put some of them back with UNSET
- One last thing: a clean-up check that found something
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 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.
SELECT * FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_DATE;| LABEL | THE_DATE | THE_STAMP |
|---|---|---|
| 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 |
Three rows, a DATE column and a TIMESTAMP_NTZ column. And here is where the session is pointing while we do all this.
SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA,
CURRENT_WAREHOUSE() AS THE_WAREHOUSE,
CURRENT_ROLE() AS THE_ROLE;| THE_DATABASE | THE_SCHEMA | THE_WAREHOUSE | THE_ROLE |
|---|---|---|---|
| DEMO_DB | PUBLIC | COMPUTE_WH | ACCOUNTADMIN |
Let's start with how many parameters a session has
SHOW PARAMETERS IN SESSION lists them all.
| key | value | default | level | description | type |
|---|---|---|---|---|---|
| ABORT_DETACHED_QUERY | false | false | If true, Snowflake will automatically abort queries when it detects that the client has disappeared. | BOOLEAN | |
| ACTIVE_PYTHON_PROFILER | Which 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_ERROR | true | true | When enabled, old fail on error behavior will be observed for AI_EMBED and AI_SIMILARITY | BOOLEAN | |
| AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR | false | false | When enabled, old fail on error behavior will be observed | BOOLEAN |
SELECT COUNT(*) AS PARAMETERS_IN_A_SESSION
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| 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.
SHOW PARAMETERS;SELECT COUNT(*) AS PARAMETERS_A_BARE_SHOW_RETURNS
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| 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.
SELECT COUNT(*) AS PARAMETERS_SOMEBODY_SET
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE NULLIF(TRIM("level"), '') IS NOT NULL;| PARAMETERS_SOMEBODY_SET |
|---|
| 8 |
Eight. And not one of them is mine. Here they are.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE NULLIF(TRIM("level"), '') IS NOT NULL
ORDER BY "key";| key | value | default | level |
|---|---|---|---|
| CLIENT_PREFETCH_THREADS | 4 | 4 | SESSION |
| ENABLE_USE_STABLE_PATH | true | false | SYSTEM |
| ODBC_QUERY_RESULT_FORMAT | ARROW | ARROW | SYSTEM |
| PYTHON_SNOWPARK_ELIMINATE_NUMERIC_SQL_VALUE_CAST_ENABLED | true | false | SYSTEM |
| PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSION | true | true | SYSTEM |
| PYTHON_SNOWPARK_USE_CTE_OPTIMIZATION_VERSION | 999.999.999 | 1.31.1 | SYSTEM |
| SNOWPARK_USE_SCOPED_TEMP_OBJECTS | false | false | SYSTEM |
| WORKSHEETS_MIGRATED | true | false | USER |
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.
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.
SHOW PARAMETERS LIKE 'TIMEZONE' IN SESSION;SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| TIMEZONE | America/Los_Angeles | America/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.
SELECT CURRENT_TIMESTAMP() AS WHAT_TIME_IT_IS,
CURRENT_TIMESTAMP()::DATE AS WHAT_DAY_IT_IS;| WHAT_TIME_IT_IS | WHAT_DAY_IT_IS |
|---|---|
| 2026-10-08 05:02:02.165000-07:00 | 2026-10-08 |
Now let's move the session to another timezone.
ALTER SESSION SET TIMEZONE = 'Asia/Karachi';| status |
|---|
| Statement executed successfully. |
SELECT CURRENT_TIMESTAMP() AS WHAT_TIME_IT_IS,
CURRENT_TIMESTAMP()::DATE AS WHAT_DAY_IT_IS;| WHAT_TIME_IT_IS | WHAT_DAY_IT_IS |
|---|---|
| 2026-10-08 17:02:02.445000+05:00 | 2026-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.
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;| IN_UTC | IN_LOS_ANGELES | IN_KARACHI |
|---|---|---|
| 2026-10-08 12:02:02.582000+00:00 | 2026-10-08 05:02:02.582000-07:00 | 2026-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.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| TIMEZONE | Asia/Karachi | America/Los_Angeles | SESSION |
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.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| WEEK_START | 0 | 0 |
Value nought, default nought, blank level. Now here is a fixed date under that setting.
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;| THE_DATE | DAY_OF_WEEK | DAY_OF_WEEK_ISO | WEEK_OF_YEAR | START_OF_ITS_WEEK |
|---|---|---|---|---|
| 2026-03-04 | 3 | 3 | 10 | 2026-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.
ALTER SESSION SET WEEK_START = 1;| status |
|---|
| Statement executed successfully. |
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| WEEK_START | 1 | 0 | SESSION |
The parameter took, and the level says SESSION. So let's run the identical date again.
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;| THE_DATE | DAY_OF_WEEK | DAY_OF_WEEK_ISO | WEEK_OF_YEAR | START_OF_ITS_WEEK |
|---|---|---|---|---|
| 2026-03-04 | 3 | 3 | 10 | 2026-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.
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.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| DATE_OUTPUT_FORMAT | YYYY-MM-DD | YYYY-MM-DD |
Year, month, day, with dashes, and a blank level. Let's change it to day, month name, year.
ALTER SESSION SET DATE_OUTPUT_FORMAT = 'DD-MON-YYYY';| status |
|---|
| Statement executed successfully. |
And now the same three rows again.
SELECT * FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_DATE;| LABEL | THE_DATE | THE_STAMP |
|---|---|---|
| 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 |
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.
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;| LABEL | THE_DATE | THE_YEAR | THE_MONTH | THE_DAY |
|---|---|---|---|---|
| first | 2026-01-31 | 2026 | 1 | 31 |
| second | 2026-06-15 | 2026 | 6 | 15 |
| third | 2026-11-02 | 2026 | 11 | 2 |
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.
ALTER SESSION SET TIMESTAMP_OUTPUT_FORMAT = 'YYYY-MM-DD"T"HH24:MI:SS';| status |
|---|
| Statement executed successfully. |
SELECT LABEL, THE_STAMP FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_STAMP;| LABEL | THE_STAMP |
|---|---|
| first | 2026-01-31 08:05:00 |
| second | 2026-06-15 14:30:45 |
| third | 2026-11-02 23:59:59 |
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.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| QUERY_TAG |
An empty value, an empty default and a blank level. Now let's set one and run something.
ALTER SESSION SET QUERY_TAG = 'episode-172-tagged';| status |
|---|
| Statement executed successfully. |
SELECT COUNT(*) AS ROWS_IN_MY_TABLE
FROM DEMO_DB.SESS_T172.WHEN_T172;| ROWS_IN_MY_TABLE |
|---|
| 3 |
Now let's go looking for that tag in the query history.
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;| QUERY_TAG | QUERY_TYPE | EXECUTION_STATUS | ROLE_NAME |
|---|---|---|---|
| episode-172-tagged | SELECT | RUNNING | ACCOUNTADMIN |
| episode-172-tagged | SELECT | SUCCESS | ACCOUNTADMIN |
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.
SELECT COUNT(*) AS QUERIES_CARRYING_MY_TAG
FROM TABLE(DEMO_DB.INFORMATION_SCHEMA.QUERY_HISTORY(RESULT_LIMIT => 200))
WHERE QUERY_TAG = 'episode-172-tagged';| 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.
ALTER SESSION SET QUERY_TAG = 'episode-172-retagged';| status |
|---|
| Statement executed successfully. |
SELECT COUNT(*) AS ROWS_AGAIN
FROM DEMO_DB.SESS_T172.WHEN_T172;| ROWS_AGAIN |
|---|
| 3 |
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;| QUERY_TAG | HOW_MANY |
|---|---|
| episode-172-retagged | 2 |
| episode-172-tagged | 5 |
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.
-- 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.
USE WAREHOUSE COMPUTE_WH;| status |
|---|
| Statement executed successfully. |
SELECT CURRENT_WAREHOUSE() AS THE_WAREHOUSE;| THE_WAREHOUSE |
|---|
| COMPUTE_WH |
Now let's put a statement timeout on our own warehouse.
ALTER WAREHOUSE WH_T172 SET STATEMENT_TIMEOUT_IN_SECONDS = 1200;| status |
|---|
| Statement executed successfully. |
SHOW PARAMETERS LIKE 'STATEMENT\_TIMEOUT\_IN\_SECONDS'
IN WAREHOUSE WH_T172;SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| STATEMENT_TIMEOUT_IN_SECONDS | 1200 | 172800 | WAREHOUSE |
Twelve hundred, and the level says WAREHOUSE. Now let's set the same parameter name on the session.
ALTER SESSION SET STATEMENT_TIMEOUT_IN_SECONDS = 300;| status |
|---|
| Statement executed successfully. |
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| STATEMENT_TIMEOUT_IN_SECONDS | 300 | 172800 | SESSION |
Three hundred, level SESSION. Let's ask the warehouse again, to be sure it did not move.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| STATEMENT_TIMEOUT_IN_SECONDS | 1200 | 172800 | WAREHOUSE |
Still twelve hundred. And now the third way of asking: the warehouse the session is actually running on, which we never touched.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| STATEMENT_TIMEOUT_IN_SECONDS | 172800 | 172800 |
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.
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.
ALTER SESSION SET
AUTOCOMMIT = TRUE,
ERROR_ON_NONDETERMINISTIC_UPDATE = TRUE,
LOCK_TIMEOUT = 600;| status |
|---|
| Statement executed successfully. |
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";| key | value | default | level |
|---|---|---|---|
| AUTOCOMMIT | true | true | SESSION |
| ERROR_ON_NONDETERMINISTIC_UPDATE | true | false | SESSION |
| LOCK_TIMEOUT | 600 | 43200 | SESSION |
All three took and all three say SESSION. Now look at the first row carefully.
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| AUTOCOMMIT | true | true | SESSION |
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.
ALTER SESSION SET MIN_DATA_RETENTION_TIME_IN_DAYS = 1;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.
ALTER SESSION SET DATA_RETENTION_TIME_IN_DAYS = 2;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.
ALTER SESSION SET NO_SUCH_PARAMETER_T172 = 1;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.
ALTER SESSION SET WEEK_START = 'Monday';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.
ALTER SESSION SET WEEK_START = 9;001008 (22023): SQL compilation error: invalid value [9] for parameter 'WEEK_START'
The same code. And a timezone that does not exist.
ALTER SESSION SET TIMEZONE = 'Mars/Olympus_Mons';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?
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| TIMEZONE | Asia/Karachi | America/Los_Angeles | SESSION |
Intact. The value we set earlier is still there. A refused SET changes nothing at all.
And last, the two syntax errors.
ALTER SESSION SET;001003 (42000): SQL compilation error: syntax error line 1 at position 17 unexpected '<EOF>'.
ALTER SESSION UNSET;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.
ALTER SESSION UNSET AUTOCOMMIT, LOCK_TIMEOUT;| status |
|---|
| Statement executed successfully. |
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";| key | value | default | level |
|---|---|---|---|
| AUTOCOMMIT | true | true | |
| ERROR_ON_NONDETERMINISTIC_UPDATE | true | false | SESSION |
| LOCK_TIMEOUT | 43200 | 43200 |
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?
ALTER SESSION UNSET JSON_INDENT;| status |
|---|
| Statement executed successfully. |
SELECT "key", "value", "default", "level"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| key | value | default | level |
|---|---|---|---|
| JSON_INDENT | 2 | 2 |
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.
-- 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.
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";| key | value | default | level |
|---|---|---|---|
| AUTOCOMMIT | true | true | |
| DATE_OUTPUT_FORMAT | YYYY-MM-DD | YYYY-MM-DD | |
| ERROR_ON_NONDETERMINISTIC_UPDATE | false | false | |
| LOCK_TIMEOUT | 43200 | 43200 | |
| QUERY_TAG | |||
| STATEMENT_TIMEOUT_IN_SECONDS | 172800 | 172800 | |
| TIMESTAMP_OUTPUT_FORMAT | YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM | YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM | |
| TIMEZONE | America/Los_Angeles | America/Los_Angeles | |
| WEEK_START | 0 | 0 |
Every level blank again, and every value back where it started. Now the check: how many parameters are still set at session level?
SELECT COUNT(*) AS PARAMETERS_STILL_SET
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE UPPER(TRIM("level")) = 'SESSION';| 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.
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;| WHAT_TIME_IT_IS | DAY_OF_WEEK | START_OF_ITS_WEEK |
|---|---|---|
| 2026-10-08 05:02:36.402000-07:00 | 3 | 2026-03-02 |
SELECT * FROM DEMO_DB.SESS_T172.WHEN_T172 ORDER BY THE_DATE;| LABEL | THE_DATE | THE_STAMP |
|---|---|---|
| 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 |
Back to the offset we started on, and the same week start as the first time we asked. Now the objects.
-- 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;SHOW WAREHOUSES;SELECT "name", "state", "size", "is_current"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
ORDER BY "name";| name | state | size | is_current |
|---|---|---|---|
| COMPUTE_WH | STARTED | X-Small | Y |
| SNOWFLAKE_LEARNING_WH | SUSPENDED | X-Small | N |
| SYSTEM$STREAMLIT_NOTEBOOK_WH | SUSPENDED | X-Small | N |
SELECT COUNT(*) AS MY_WAREHOUSES_LEFT
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));| MY_WAREHOUSES_LEFT |
|---|
| 0 |
SELECT COUNT(*) AS MY_SCHEMAS_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME = 'SESS_T172';| MY_SCHEMAS_LEFT |
|---|
| 0 |
Three warehouses, none of them ours, and nothing of ours left in the database either.
SELECT CURRENT_ROLE() AS THE_ROLE, CURRENT_SECONDARY_ROLES() AS THE_SECONDARY_ROLES;| THE_ROLE | THE_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 SESSIONreturned 161 rows, and a bareSHOW PARAMETERSreturned 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
WAREHOUSElevel, 300 atSESSIONlevel, 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. TIMEZONEand the output formats change how a value is rendered. The stored year, month and day never moved.QUERY_TAGapplies from the moment you set it onwards, and retagging mid-session does not retag what already ran.001006is the answer for a real parameter in the wrong place and for a name that does not exist.001008is a bad value, and001003is aSETorUNSETwith nothing after it.- A refused
SETleaves the parameter exactly as it was. UNSETremoves 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.
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.