Get started with Secoda
See why hundreds of industry leaders trust Secoda to unlock their data's full potential.
See why hundreds of industry leaders trust Secoda to unlock their data's full potential.
Snowflake query tags are descriptive string labels up to 2000 characters long that can be attached to individual queries or groups of queries to help organize and categorize them for tracking and reporting purposes. These tags facilitate query tracking, tuning, and optimization within the Snowflake ecosystem.
Snowflake query tags can be configured at various levels to provide flexibility and granular control:
Query tags are specifically designed to be attached to queries. They help in organizing and categorizing queries to facilitate performance optimization and tracking. In contrast, object tags are attached to database objects such as tables, views, and schemas. They are used for data management, access control, and data retention policies.
Feature Query Tags Object Tags Purpose Organize and track queries Manage and control data objects Attachment Queries Database objects (tables, views) Usage Performance optimization Data management and policies
Begin by logging into your Snowflake account and creating a worksheet where you will execute your SQL commands.
CREATE DATABASE awesome_database;
This command creates a new database named awesome_database.
USE DATABASE awesome_database;
This command sets the context to the newly created database.
CREATE WAREHOUSE awesome_warehouse;
This command creates a new warehouse named awesome_warehouse.
USE WAREHOUSE awesome_warehouse;
This command sets the context to the newly created warehouse.
CREATE TABLE awesome_table (
id INT,
name VARCHAR,
age INT
);
This command creates a new table named awesome_table with columns for id, name, and age.
INSERT INTO awesome_table VALUES (1, 'Johnny', 25), (2, 'Happy', 30), (3, 'Chaos', 40);
This command inserts sample data into the awesome_table.
ALTER SESSION SET QUERY_TAG = 'Some_query_tag_name';
This command sets a session-level query tag named Some_query_tag_name.
SELECT * FROM awesome_table;
This command runs a query to select all data from the awesome_table with the session-level query tag applied.
SELECT QUERY_TAG FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY()) WHERE QUERY_TEXT LIKE 'SELECT * FROM awesome_table%';
This command verifies the query tag by checking the query history.
Account-level query tags apply to all queries within the account, user-level query tags override account-level tags for specific users, and session-level query tags have the highest priority and override both account and user-level tags.
USE ROLE ACCOUNTADMIN;
ALTER ACCOUNT SET QUERY_TAG = 'Account_level_query_tag';
The order of precedence for query tags ensures that the most specific tag is applied:
Level Priority Session Highest User Overrides account-level if set Account Default if no user or session tags