snow stage execute¶
立即执行暂存区路径中的所有文件。可使用类 glob 的模式过滤文件,例如 @stage/*.sql、@stage/dev/*。只执行扩展名为 .sql 的文件。
语法¶
snow stage execute
<stage_path>
--on-error <on_error>
--variable <variables>
--connection <connection>
--host <host>
--port <port>
--account <account>
--user <user>
--password <password>
--authenticator <authenticator>
--workload-identity-provider <workload_identity_provider>
--private-key-file <private_key_file>
--token <token>
--token-file-path <token_file_path>
--database <database>
--schema <schema>
--role <role>
--warehouse <warehouse>
--temporary-connection
--mfa-passcode <mfa_passcode>
--enable-diag
--diag-log-path <diag_log_path>
--diag-allowlist-path <diag_allowlist_path>
--oauth-client-id <oauth_client_id>
--oauth-client-secret <oauth_client_secret>
--oauth-authorization-url <oauth_authorization_url>
--oauth-token-request-url <oauth_token_request_url>
--oauth-redirect-uri <oauth_redirect_uri>
--oauth-scope <oauth_scope>
--oauth-disable-pkce
--oauth-enable-refresh-tokens
--oauth-enable-single-use-refresh-tokens
--client-store-temporary-credential
--format <format>
--verbose
--debug
--silent
--enhanced-exit-codes
实参¶
stage_path包含待执行文件的暂存区路径。例如
@stage/dev/*。
选项¶
--on-error [break|continue]出现错误时该怎么办?默认为中断。默认值:break。
--variable, -D TEXT执行上下文的变量;例如:
-D "<key>=<value>"。对于 SQL 文件,变量用于扩展模板,任何未知变量都会导致错误(考虑在文件中加上引号)。对于 Python 文件,变量用于更新 os.environ 字典。所提供的键值均大写,以符合最佳实践。如果 SQL 文件字符串值必须用 `''`加引号(考虑在文件中嵌入引用)。--connection, -c, --environment TEXT连接名称,如您在
config.toml文件中所定义。默认值:default。--host TEXT连接的主机地址。替换为连接指定的值。
--port INTEGER连接的端口。替换为连接指定的值。
--account, --accountname TEXT分配给 Snowflake 账户的名称。替换为连接指定的值。
--user, --username TEXT连接到 Snowflake 的用户名。替换为连接指定的值。
--password TEXTSnowflake 密码。替换为连接指定的值。
--authenticator TEXTSnowflake 身份验证器。替换为连接指定的值。
--workload-identity-provider TEXTWorkload identity provider (AWS, AZURE, GCP, OIDC). Overrides the value specified for the connection.
--private-key-file, --private-key-path TEXTSnowflake 私钥文件路径。替换为连接指定的值。
--token TEXT连接到 Snowflake 时使用的 OAuth 令牌。
--token-file-path TEXT连接到 Snowflake 时使用的带有 OAuth 令牌的文件路径。
--database, --dbname TEXT要使用的数据库。替换为连接指定的值。
--schema, --schemaname TEXT要使用的数据库架构。替换为连接指定的值。
--role, --rolename TEXT要使用的角色。替换为连接指定的值。
--warehouse TEXT要使用的仓库。替换为连接指定的值。
--temporary-connection, -x使用命令行参数定义的连接,而不是在配置中定义的连接。默认值:False。
--mfa-passcode TEXT用于多重身份验证的令牌 (MFA)。
--enable-diag是否生成连接诊断报告。默认值:False。
--diag-log-path TEXT生成的报告的路径。默认为系统临时目录。默认:<system_temporary_directory>。
--diag-allowlist-path TEXT包含允许列表参数的 JSON 文件的路径。
--oauth-client-id TEXT身份提供商为 Snowflake 集成提供的客户端 ID 的值。
--oauth-client-secret TEXT身份提供商为 Snowflake 集成提供的客户端密钥的值。
--oauth-authorization-url TEXT向驱动程序提供授权码的身份提供商端点。
--oauth-token-request-url TEXT向驱动程序提供访问令牌的身份提供商端点。
--oauth-redirect-uri TEXTURI 用于授权码重定向。
--oauth-scope TEXT身份提供商授权请求中请求的范围。
--oauth-disable-pkce禁用代码交换证明密钥 (PKCE)。默认值:
False。--oauth-enable-refresh-tokens在实际访问令牌过期时启用静默重新身份验证。默认值:
False。--oauth-enable-single-use-refresh-tokens是否选择启用一次性刷新令牌语义。默认值:
False。--client-store-temporary-credential存储临时凭据。
--format [TABLE|JSON|JSON_EXT|CSV]指定输出格式。默认:TABLE。
--verbose, -v显示日志级别
info及更高级别的日志条目。默认值:False。--debug显示日志级别
debug及更高级别的日志条目;调试日志包含其他信息。默认值:False。--silent关闭到控制台的中间输出。默认值:False。
--enhanced-exit-codes根据错误类型区分退出错误代码。默认值:False。
--help显示此命令的帮助文本。
使用说明¶
备注
Snowflake CLI 不支持执行 Python 3.12 及以上版本的 Python 文件。
该命令在指定的
STAGE_PATH中搜索扩展名为.sql的文件,并在每个文件上执行 executesEXECUTE IMMEDIATE。STAGE_PATH可以是:只是一个暂存文件名,如
@scripts,执行该暂存区中的所有.sql文件。类 glob 模式,如
@scripts/dir/*,执行dir目录中的.sql文件。直接文件路径,如
@scripts/script.sql,只执行来自scripts的script.sql文件。
--silent 选项会隐藏文件执行结果的中间信息。
当使用 SQL 文件的 Jinja 模板时,您可以使用 -D``(或 ``--variable)选项,例如 -D "<密钥>=<value>"。您必须用单引号括起字符串值 ('')。
示例¶
只指定暂存区名称,执行该暂存区中的所有
.sql文件:snow stage execute "@scripts"
SUCCESS - scripts/script1.sql SUCCESS - scripts/script2.sql SUCCESS - scripts/dir/script.sql +------------------------------------------+ | File | Status | Error | |------------------------+---------+-------| | scripts/script1.sql | SUCCESS | None | | scripts/script2.sql | SUCCESS | None | | scripts/dir/script.sql | SUCCESS | None | +------------------------------------------+
指定一个类 glob 模式,以执行
dir目录中的所有.sql文件:snow stage execute "@scripts/dir/*"
SUCCESS - scripts/dir/script.sql +------------------------------------------+ | File | Status | Error | |------------------------+---------+-------| | scripts/dir/script.sql | SUCCESS | None | +------------------------------------------+
指定类 glob 的模式,只执行
dir目录中以“script”开头、后跟一个字符的.sql文件:snow stage execute "@scripts/script?.sql"
SUCCESS - scripts/script1.sql SUCCESS - scripts/script2.sql +---------------------------------------+ | File | Status | Error | |---------------------+---------+-------| | scripts/script1.sql | SUCCESS | None | | scripts/script2.sql | SUCCESS | None | +---------------------------------------+
使用
--silent选项指定直接文件路径:snow stage execute "@scripts/script1.sql" --silent
+---------------------------------------+ | File | Status | Error | |---------------------+---------+-------| | scripts/script1.sql | SUCCESS | None | +---------------------------------------+