BigQuery 命令行工具“bq query”如何进行查询?停止打印某些作业的 sql 查询字符串?
假设当前目录中存在以下文件:
# example1.sql
SELECT 1 AS data
当我运行 bq query --use_legacy_sql=false --format=csv example1.sql
我得到了预期的输出:
Waiting on bqjob_r1cc6530a5317399f_0000017f2b966269_1 ... (0s) Current status: DONE
data
1
但是,如果我运行以下查询
# example2.sql
DECLARE useless_variable_1 STRING DEFAULT 'var_1';
DECLARE useless_variable_2 STRING DEFAULT 'var_2';
SELECT 1 AS data;
,例如 bq query --use_legacy_sql=false --format=csv < example2.sql 我得到以下输出:
Waiting on bqjob_r501cc26a3d336b7c_0000017f2b97ceb1_1 ... (0s) Current status: DONE
SELECT 1 AS data; -- at [6:1]
data
1
如您所见,添加变量导致 bq query 将“example2.sql”的内容打印到 stdout,这不是我想要的。如何避免将文件内容打印到标准输出,而只是像第一个示例一样返回查询结果?
Let's say the following file exists in the current directory:
# example1.sql
SELECT 1 AS data
When I run bq query --use_legacy_sql=false --format=csv < example1.sql
I get the expected output:
Waiting on bqjob_r1cc6530a5317399f_0000017f2b966269_1 ... (0s) Current status: DONE
data
1
But if I run the following query
# example2.sql
DECLARE useless_variable_1 STRING DEFAULT 'var_1';
DECLARE useless_variable_2 STRING DEFAULT 'var_2';
SELECT 1 AS data;
like this bq query --use_legacy_sql=false --format=csv < example2.sql
I get the following output:
Waiting on bqjob_r501cc26a3d336b7c_0000017f2b97ceb1_1 ... (0s) Current status: DONE
SELECT 1 AS data; -- at [6:1]
data
1
As you can see, adding variables caused bq query
to print the contents of "example2.sql" to stdout, which is not what I want. How can I avoid printing the contents of the file to stdout and instead just return the result of the query like in the first example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论