Practical SQL

Using the bq CLI utility with BigQuery

Constantin LunguUpdated 1 min read

Photo by Gabriel Heinzer on Unsplash

Remember that in additional to the Cloud Console GUI or client libraries, you can also perform BigQuery tasks using the bq command-line interface.

It's included with the gcloud SDK and once you have logged in, you can perform a number of operations such as:
- run queries against BQ
- create, copy and delete tables
- load data into tables
- view IAM policies for a BQ asset and much more

How I've used it until now:
- impersonate service accounts
- perform operations that are/were not supported in the SQL interface, such as copying partitions between tables

Any other interesting ways you're using the bq cli tool?

bq query --use_legacy_sql=false "SELECT * FROM learning.employee_data"

Terminal output: an ASCII table of nine employees with employee_id, first_name, last_name and manager_id: John Smith has manager_id NULL, Jane Doe and Bob Johnson report to 1, Alice Lee and Tom Wilson to 2, Mike Brown and Sarah Kim to 3, David Lee and Emily Davis to 4.


Enjoyed this? Here are some related articles you might find useful: