6

是否可以在 bigquery CLI 中使用输入文件?

bq query < my_query.sql
4

3 回答 3

14

如果您使用的是 unix(或在 Windows 上安装了 cygwin),则可以使用 xargs:

xargs -a my_query.sql -0 bq query

或者,您可以使用反引号:

bq query `cat my_query.sql`

请注意,bq 一次只能处理一个命令——如果您的 .sql 脚本有多个查询,则需要将文件拆分为 ;

于 2012-09-07T21:12:45.850 回答
2

我无法使用其他解决方案来处理非常长且复杂的查询,尤其是那些带有任何引号的查询。我有更多的运气将文件传送到 bq 工具中

cat test.sql | bq query
于 2020-01-31T14:48:21.727 回答
0

在 Windows 上,我正在使用这种方法。先决条件是将每个命令列在一行中。这将使用 bq 逐一处理行中的每个命令。

C:\temp>for /F "tokens=*" %A in (batch_query.sql) do bq query %A

C:\temp>bq query select count+1 from cmdwh_bq_prod.newtable ;
Waiting on bqjob_r63bf8c82_00000163004c7fd0_1 ... (0s) Current status: DONE
+-------+
|  f0_  |
+-------+
| 20136 |
+-------+

C:\temp>bq query select count+2 from cmdwh_bq_prod.newtable ;
Waiting on bqjob_r7ffd9b2a_00000163004c9348_1 ... (0s) Current status: DONE
+-------+
|  f0_  |
+-------+
| 20137 |
+-------+

C:\temp>bq query select count+3 from cmdwh_bq_prod.newtable ;
Waiting on bqjob_r223c57a3_00000163004ca682_1 ... (0s) Current status: DONE
+-------+
|  f0_  |
+-------+
| 20138 |
+-------+

C:\temp>
C:\temp>type batch_query.sql
select count+1 from cmdwh_bq_prod.newtable ;
select count+2 from cmdwh_bq_prod.newtable ;
select count+3 from cmdwh_bq_prod.newtable ;

C:\temp>bq query select * from cmdwh_bq_prod.newtable
Waiting on bqjob_r3a363e1b_00000163004f4dba_1 ... (0s) Current status: DONE
+-------+
| count |
+-------+
| 20135 |
+-------+

C:\temp>
于 2018-04-26T04:57:45.933 回答