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>
--private-key-file <private_key_file>
--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>
--format <format>
--verbose
--debug
--silent
实参¶
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 TEXT
Snowflake 密码。替换为连接指定的值。
--authenticator TEXT
Snowflake 身份验证器。替换为连接指定的值。
--private-key-file, --private-key-path TEXT
Snowflake 私钥文件路径。替换为连接指定的值。
--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
运行 Python 连接器诊断测试。默认值:False。
--diag-log-path TEXT
诊断报告路径。默认:<temporary_directory>。
--diag-allowlist-path TEXT
可选允许列表的诊断报告路径。
--format [TABLE|JSON]
指定输出格式。默认:TABLE。
--verbose, -v
显示日志级别
info
及更高级别的日志条目。默认值:False。--debug
显示日志级别
debug
及更高级别的日志条目;调试日志包含其他信息。默认值:False。--silent
关闭到控制台的中间输出。默认值: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 | +---------------------------------------+