暂存文件中 Select 中的列绑定变量 #snowflake-cloud-platform

Column bind variable in Select on Staged File #snowflake-cloud-platform

为了暂存和查询文件,文档显示了这个示例查询: SELECT t.$1, t.$2 来自@mystage1 (file_format => myformat) t;

为了简化字符串操作,我想将 Snowflake 配置为使用美元符号以外的任何内容作为列引用。例如,用 c 代替 $?

怎么样?

SELECT t.c1, t.c2 来自@mystage1 (file_format => myformat) t;

这是文档的 link: https://docs.snowflake.com/en/user-guide/querying-stage.html

目前,我被一个应用程序强制使用 PowerShell 来编写要由 SnowSql CLI 处理的查询)。让 PowerShell 发出这个字符串是微不足道的,但是 SnowSql 会添加它的两分钱,并且历史记录显示该语句被处理为 SELECT t., t. FROM @mystage1 (file_format => myformat) t;

PowerShell follows a quoting rule similar to Bash,其中 $VARIABLE 在双引号字符串中总是解析,在单引号字符串中从不解析。

syntax for stage querying 需要使用不能替代其他字符串的 $ 符号。

如果您无法使用文件将查询传递给 SnowSQL(通过其 -f [FILE] option) as a way of stepping around the shell parsing, and have to use the -q [TEXT] option,请考虑转义 $ 符号,或者使用无法解析的引号(单引号字符: ') 或使用 PowerShell 转义字符(反引号字符:`):

snowsql -q 'SELECT t., t. FROM @mystage1 (file_format => myformat) t;'
snowsql -q "SELECT t.`, t.` FROM @mystage1 (file_format => myformat) t;"