Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bigquery command line tool to read long query string from a file

I am using the Bigquery command line tool to query data from a Bigquery table.

My query statement is very long.

Is there a way to save the long query statement in a file and pass the file name to the Bigquery command line tool?

Thank you.

like image 273
user3709284 Avatar asked Jul 31 '14 22:07

user3709284


People also ask

How do you read a BigQuery?

BigQuery allows you to run complex analytical queries on large sets of data. Queries are requests for data that can include calculation, modification, merging, and other manipulations with data. Let's say, in Google Sheets, you can also query data sets using the QUERY function.

How do you use the bq command-line tool?

You can run the bq command-line tool in an interactive shell where you don't need to prefix the commands with bq . To start interactive mode, enter bq shell . After launching the shell, the prompt changes to the ID of your default project. To exit interactive mode, enter exit .

Which CLI tool is used to interact with BigQuery service?

The bq command-line tool accepts the following formats for setting boolean flags. This document uses the -- FLAGNAME = VALUE format for boolean flags. All boolean flags are optional; if a boolean flag is not present, then BigQuery uses the flag's default value.


2 Answers

You can use this:

cat query.txt | bq query
like image 155
Renato Avatar answered Nov 03 '22 01:11

Renato


Just use cat in tick marks. Switch the double quotes to single quotes if needed.

bq query "`cat query.txt`"

like image 36
Andrew Ryno Avatar answered Nov 03 '22 01:11

Andrew Ryno