有没有办法在不会导致错误的情况下在 SnowSQL 文件中添加注释?
is there a way to put comments in SnowSQL files that do not cause errors?
我正在使用带有 snowsql 的文件来自动执行某些流程。为了维护,我想在文件中包含注释(在行首使用 //
)来解释关键步骤。但是,我这样做时snowsql报错:000900 (42601): SQL compilation error: Empty SQL statement.
例如:
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 语句。尽管它正确地发现它只是一条注释,但它正在尝试执行并且没有找到实际的脚本。因此 "Empty SQL statement."
作为解决方法您应该能够将注释放在分号之前,以便它意识到 运行.
只有一个脚本
您也可以放入一个虚拟 select 1
或类似的东西。
select 'hello world'
// and now exit the session
;
!exit
您可以使用标准的 SQL 注释标记,双破折号。我测试了它,它有效:
select 'hello world';
-- and now exit the session
!exit
我认为如果它在网络上有效UI它应该在 SnowSQL 中以相同的方式工作SQL,所以我会打开一个工单来检查这个。
不确定是否存在问题...尽管 !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
...注意脚本末尾有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 语句,但它们混淆了脚本的结尾!
最后,我确实用双破折号替换了最后一行的双斜杠,并且出现了 no SQL 编译错误。在命令行执行步骤中没有 echo=True 选项的结果相同。
我认为这与我自己的问题有关,即通过 snowsql 命令行调用时显然无法退出脚本。 (参见问题 login.sql and NOT exit)
我正在使用带有 snowsql 的文件来自动执行某些流程。为了维护,我想在文件中包含注释(在行首使用 //
)来解释关键步骤。但是,我这样做时snowsql报错:000900 (42601): SQL compilation error: Empty SQL statement.
例如:
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 语句。尽管它正确地发现它只是一条注释,但它正在尝试执行并且没有找到实际的脚本。因此 "Empty SQL statement."
作为解决方法您应该能够将注释放在分号之前,以便它意识到 运行.
只有一个脚本您也可以放入一个虚拟 select 1
或类似的东西。
select 'hello world'
// and now exit the session
;
!exit
您可以使用标准的 SQL 注释标记,双破折号。我测试了它,它有效:
select 'hello world';
-- and now exit the session
!exit
我认为如果它在网络上有效UI它应该在 SnowSQL 中以相同的方式工作SQL,所以我会打开一个工单来检查这个。
不确定是否存在问题...尽管 !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
...注意脚本末尾有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 语句,但它们混淆了脚本的结尾!
最后,我确实用双破折号替换了最后一行的双斜杠,并且出现了 no SQL 编译错误。在命令行执行步骤中没有 echo=True 选项的结果相同。
我认为这与我自己的问题有关,即通过 snowsql 命令行调用时显然无法退出脚本。 (参见问题 login.sql and NOT exit)