雪花云数据平台-有没有一种方法可以在SnowSQL文件中放入不会导致错误的注释



我使用带有snowsql的文件来自动化某些过程。对于维护,我想在文件中包含注释(在行的开头使用//(来解释关键步骤。然而,当我这样做时,snowsql报告了一个错误:000900(42601(:SQL编译错误:空SQL语句

例如:

select 'hello world';
// and now exit the session
!exit

将导致错误:

$ snowsql --filename comments.sql
* SnowSQL * v1.2.5approval |                     
Type SQL statements or !help                     
+---------------+                                
| 'HELLO WORLD' |                                
|---------------|                                
| hello world   |                                
+---------------+                                
1 Row(s) produced. Time Elapsed: 0.209s          
000900 (42601): SQL compilation error:           
Empty SQL statement.                             
Goodbye!                                         

如果我删除评论并留下空行:

select 'hello world';
!exit

然后它工作,没有错误报告

$ snowsql --filename no-comments.sql
* SnowSQL * v1.2.5approval |
Type SQL statements or !help
+---------------+
| 'HELLO WORLD' |
|---------------|
| hello world   |
+---------------+
1 Row(s) produced. Time Elapsed: 1.088s
Goodbye!

snowsql 1.2.5版会出现这种情况

有没有一种方法可以在sql文件中包含不会导致snowsql错误的注释?

您可以使用标准的SQL注释标记,双破折号。我测试了它,它有效:

select 'hello world';
-- and now exit the session
!exit

我认为如果它在web UI中工作,那么它在SnowSQL中也应该以同样的方式工作,所以我会打开一张罚单来检查这一点。

问题似乎是它将注释文本视为sql语句。尽管它正确地发现它只是一个注释,但它正在尝试执行,却没有找到实际的脚本。因此"空SQL语句"。

作为一种变通方法,您应该能够将注释放在分号之前,以便它意识到只有一个脚本可以运行。

您也可以放入一个伪select 1或类似的东西。

select 'hello world'
// and now exit the session
;
!exit

不确定是否有问题。。。尽管CCD_ 3可能是个问题。首先,另一个例子:

我的comments.sql:测试

select 'hello Grovers Corner';
-- this is a double dash comment
select 'hello Indiana'
-- dashes in middle of sql statement
from information_schema.tables
fetch 1 row only;
select 'hello United States'
// slashes in middle of sql statement
from information_schema.tables
fetch 1 row only;
// some final slashes on the last line

请注意,在脚本的末尾有no!exit

以及snowsql执行结果:

$ snowsql -f comments.sql -o echo=True
* SnowSQL * v1.1.86
Type SQL statements or !help
select 'hello Grovers Corner';
+------------------------+
| 'HELLO GROVERS CORNER' |
|------------------------|
| hello Grovers Corner   |
+------------------------+
1 Row(s) produced. Time Elapsed: 0.085s
-- this is a double dash comment
select 'hello Indiana'
-- dashes in middle of sql statement
from information_schema.tables
fetch 1 row only;
+-----------------+
| 'HELLO INDIANA' |
|-----------------|
| hello Indiana   |
+-----------------+
1 Row(s) produced. Time Elapsed: 1.803s
select 'hello United States'
// slashes in middle of sql statement
from information_schema.tables
fetch 1 row only;
+-----------------------+
| 'HELLO UNITED STATES' |
|-----------------------|
| hello United States   |
+-----------------------+
1 Row(s) produced. Time Elapsed: 1.748s
// some final slashes on the last line
000900 (42601): SQL compilation error:
Empty SQL statement.
Goodbye!
$

因此,双斜杠并没有影响sql语句,但它们混淆了脚本的结尾!

最后,我确实用双短划线替换了最后一行的双斜杠,并且没有SQL编译错误。在命令行执行步骤中,如果没有echo=True选项,也会得到相同的结果。

我认为这与我自己的问题有关,即当通过snowsql命令行调用脚本时,显然无法不退出脚本。(请参阅SO问题登录.sql并不要退出(

相关内容

最新更新