0

我正在使用带有 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 错误的注释?

4

3 回答 3

0

看起来问题在于它将注释文本视为 sql 语句。即使它正确地发现它只是一个注释,它也在尝试执行并且没有找到实际的脚本。因此“空 SQL 语句”。

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

你也可以放一个假人select 1或类似的东西。

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

!exit
于 2020-03-26T17:24:21.893 回答
0

不确定是否有问题……尽管这!exit可能是个问题。首先,另一个例子:

我对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

...注意脚本末尾没有 !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 问题login.sql 并且不退出

于 2020-04-21T15:38:46.933 回答
0

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

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

我认为如果它在 Web UI 中工作,它应该在 SnowSQL 中以相同的方式工作,所以我将打开一张票来检查这一点。

于 2020-03-26T18:22:21.043 回答