【问题标题】:Snowflake CLI (Snowsql) - query taggingSnowflake CLI (Snowsql) - 查询标记
【发布时间】:2018-06-21 09:52:20
【问题描述】:

当从 snowsql shell 运行查询时,我会在 UI 上看到生成的查询 ID。稍后如果我必须在历史记录中搜索相同的内容,我想搜索我可以定义的查询 id 或以某种方式标记查询。

在我运行查询时是否可以创建自己的查询 ID 或标签?

【问题讨论】:

    标签: sql tagging snowflake-cloud-data-platform snowsql


    【解决方案1】:

    您无法创建自己的查询 ID,但可以使用 QUERY_TAG 参数,请参阅 here

    您可以稍后在扫描INFORMATION_SCHEMA.QUERY_HISTORY 表时使用它,请参阅here,它有一个QUERY_TAG 列。您还可以在 UI 的 History 选项卡中使用 Query Tag 过滤器。

    您还可以使用LAST_QUERY_ID 以编程方式获取雪花生成的QUERY_ID。然后在 QUERY_HISTORY 表和 UI 中使用它进行过滤。

    【讨论】:

      【解决方案2】:

      您实际上并未在 CLI 中提供此内容:

      如果您有 SQL 脚本 (running_test.sql):

      更改会话集 QUERY_TAG = ; /* 后跟 SQL */

      然后你以正常方式调用 snowsql cli:

      snowsql -c "CONNECTION_NAME" -f "full_path_to_sql_file" > write_to_log_file

      (连接名称是您在配置文件中设置的名称)

      或 snowsql "account_details + username + password" -f "full_path_to_sql_file" > write_to_log_file

      【讨论】:

        【解决方案3】:

        您可以为帐户、用户或会话设置查询标签。这在跨多个服务跟踪查询行为时特别有用。

        请注意,设置 QUERY_TAG 将按更精细的级别(帐户 > 用户 > 会话)设置 act as a default and will be overridden

        /* 
          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'
        ;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-10-14
          • 1970-01-01
          • 2023-02-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-02-04
          • 2020-12-21
          相关资源
          最近更新 更多