How does the BigQuery command line tool "bq query" stop printing the sql query string for some jobs?

350 Views Asked by At

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?

0

There are 0 best solutions below