Google Bigquery BQ command line execute query from a file

后端 未结 6 579
天涯浪人
天涯浪人 2020-12-19 04:49

I use the bq command line tool to run queries, e.g:

bq query "select * from table"

What if I store the query in a file

6条回答
  •  北海茫月
    2020-12-19 05:33

    You can run a query from a text file with a little bit of shell magic:

    $ echo "SELECT 17" > qq.txt
    $ bq query "$(cat qq.txt)"
    
    Waiting on bqjob_r603d91b7e0435a0f_00000150c56689c6_1 ... (0s) Current status: DONE   
    +-----+
    | f0_ |
    +-----+
    |  17 |
    +-----+
    

    Note this works on any unix variant (including mac). If you're using a windows, this should work under powershell but not the default cmd prompt.

提交回复
热议问题