Export results from BigQuery to a file using the bq query command

Is there a way to export results from BigQuery to a csv file using

bq query "SELECT name, count FROM mydataset.babynames WHERE gender = 'M' ORDER BY count DESC LIMIT 6" .

I found that we can specify the parameter --destination_table = mydataset.happyhalloween, which will be written to another table. Is there a way to write to a file?

I also tried bq query "SELECT name, count FROM mydataset.babynames WHERE gender = 'M' ORDER BY count DESC LIMIT 6"> output.txt

But this creates additional headers. enter image description here

But I want the results to be written to a file

, : bq query --format = csv "SELECT commit FROM [bigquery-public-data: github_repos.commits] LIMIT 10" > output.txt , output.txt

enter image description here

+4
1

bq . bq -help.

:

--apilog - Turn on logging of all server requests and responses. If no string is provided (--apilog=), log to stdout; if a string is provided, instead log to that file (--apilog=filename).

--format [none|json|prettyjson|csv|sparse|pretty] - The output format.
+3

Source: https://habr.com/ru/post/1651391/


All Articles