Reputation: 9014
When a query is run from the snowsql shell, i get to see the generated query id on the UI. Later on if i have to search for the same in the history, i want to search the query id that i can define or someway to tag the query.
Is it possible to create my own query id or tag when i run the query?
Upvotes: 4
Views: 7037
Reputation: 12058
You can set a query tag for an account, user, or session. This is particularly helpful when tracking query behavior across many services.
Note that setting QUERY_TAG
will act as a default and will be overridden by more granular levels (account > user > session).
/*
The following will provide a default query tag to all queries
performed by an account (replace `MY_ACCOUNT` with your account name)
*/
ALTER ACCOUNT MY_ACCOUNT SET
QUERY_TAG = 'Data Warehouse'
;
/*
The following will provide a default query tag to all queries
performed by a user (replace `MY_USER` with your user name)
NOTE: This is more granular than ACCOUNT and will override
default QUERY_TAG
*/
ALTER USER MY_USER SET
QUERY_TAG = 'Data Transformations'
;
/*
The following will provide a query tag to all queries
performed by this session.
NOTE: This is more granular than USER and ACCOUNT and
will override default QUERY_TAG
*/
ALTER SESSION SET
QUERY_TAG = 'Doing this very specific task'
;
Upvotes: 1
Reputation: 588
You don't actually supply this at the CLI:
if you have a SQL script (running_test.sql):
ALTER SESSION SET QUERY_TAG = ; /* followed by SQL */
Then you call snowsql cli in normal fashion:
snowsql -c "CONNECTION_NAME" -f "full_path_to_sql_file" > write_to_log_file
(Connection name is something you set in your config file)
or snowsql "account_details + username + password" -f "full_path_to_sql_file" > write_to_log_file
Upvotes: 2
Reputation: 4729
You can't create your own query id, but you can use the QUERY_TAG
parameter, see here.
You can later use it when scanning the INFORMATION_SCHEMA.QUERY_HISTORY
table, see here, it has a QUERY_TAG
column. You can also use a Query Tag
filter in the History
tab in the UI.
You can also use LAST_QUERY_ID to obtain the Snowflake-generated QUERY_ID
programmatically. And then you it to filter with that in the QUERY_HISTORY
table, and also in the UI.
Upvotes: 6