Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a SQL source file with the bigquery cli

Is it possible to use an input file with the bigquery CLI?

bq query < my_query.sql
like image 904
SemperFly Avatar asked Sep 07 '12 18:09

SemperFly


2 Answers

If you're using unix (or have cygwin installed on windows), you can use xargs:

xargs -a my_query.sql -0 bq query

Alternately you can use back-ticks:

bq query `cat my_query.sql`

Note that bq can only process one command at a time -- if your .sql script has several queries, you'll need to split the file on ;

like image 72
Jordan Tigani Avatar answered Sep 23 '22 08:09

Jordan Tigani


I wasn't able to get the other solutions to work with very long and complex queries, particularly those with any kind of quote marks in them. I've had more luck piping the file into the bq tool

cat test.sql | bq query
like image 34
Holt Skinner Avatar answered Sep 21 '22 08:09

Holt Skinner