首页 > 解决方案 > 如何从雪花中的“存储集成”中选择价值?

问题描述

我通过执行以下命令创建了存储集成

create or replace storage integration stager 
       type = external_stage
       storage_provider = s3
       enabled = true
       storage_aws_role_arn = 'arn:aws:iam::24545426:role/test'
       storage_allowed_locations = ('s3://testb/')

之后我执行了DESC INTEGRATION stager

我得到了像

在此处输入图像描述

现在我想要选择STORAGE_AWS_EXTERNAL_IDproperty valuestager

如何选择 STORAGE_AWS_EXTERNAL_IDproperty value 使用查询或python?

标签: python-3.xsnowflake-cloud-data-platformsnowflake-schema

解决方案


您可以使用 RESULT_SCAN 函数来处理另一个查询的结果(使用 SQL):

https://docs.snowflake.com/en/sql-reference/functions/result_scan.html

https://docs.snowflake.com/en/sql-reference/functions/result_scan.html#examples-using-describe-and-show-commands

对于蟒蛇:

import snowflake.connector

ctx = snowflake.connector.connect(
      ...
) 


cs = ctx.cursor()

try:
    sql = "DESC INTEGRATION stager"
    cs.execute( sql )
    for (c_property, c_type, c_value, c_default) in cs:
        if c_property == "STORAGE_AWS_EXTERNAL_ID":
            print('{0}, {1}'.format(c_property, c_value))


finally:
    cs.close()

这是上述 Python 脚本的结果:

STORAGE_AWS_EXTERNAL_ID, WX65722_SFCRole=2_GpY+ZF0b41Nu3d2ZDFYPfCUbBxk=

推荐阅读