Pablo
Pablo

Reputation: 3514

using a sql script storaged in gcs on bigquery

I'm trying to use a .sql file saved on Google Cloud Storage to query BigQuery

I'm trying with the bq command docs without success.

bq query --use_legacy_sql=false < gs://bucket/path-to-file/file.sql Is the command misused ?

Upvotes: 0

Views: 1013

Answers (2)

yavalvas
yavalvas

Reputation: 330

Use can use both:

bq query --nouse_legacy_sql

and

bq query --use_legacy_sql=false

Check whether you have access to that bucket in Storage and copy the file to a local folder if it's not so large:

gsutil cp gs://bucket/path-to-file/file.sql .

Try to apply that file

bq query --nouse_legacy_sql << file.sql

You can try such trick if the file isn't large:

bq query --nouse_legacy_sql "$(gsutil cat gs://bucket/path-to-file/file.sql)"

Upvotes: 1

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172994

The file with script should be local to your gcloud instance
Assuming file.sql is in your working directory - below example would work

bq query --use_legacy_sql=false < file.sql    

So, in your case you need to use gsutil to first load file.sql from GCS to your directory

gsutil cp gs://bucket/path-to-file/file.sql .
bq query --use_legacy_sql=false < file.sql

Upvotes: 0

Related Questions