bq
Google BigQuery command-line interface
TLDR
SYNOPSIS
bq [options] command
DESCRIPTION
bq is the Python-based command-line interface for Google BigQuery, shipped as part of the Google Cloud CLI (gcloud). It enables querying massive datasets, managing tables and datasets, loading data, and controlling access through a unified interface.Resources are addressed as PROJECT:DATASET.TABLE; the project prefix can be omitted when a default project is configured. Commands take the form bq COMMAND [FLAGS] [ARGUMENTS], where global flags (such as --project_id) work across commands and command-specific flags apply to a single command.
PARAMETERS
--project_id id
Project ID--dataset_id id
Dataset ID--format format
Output format (json, csv, prettyjson)--max_rows n
Maximum rows to return--use_legacy_sql=false
Use GoogleSQL (standard SQL) instead of the legacy dialect. Recommended.--location region
Region or multi-region for the job or resource (for example US, EU, asia-northeast1).--dry_run
Validate the query and report bytes processed without executing it.--apilog file
Log API requests and responses to a file (use - for stdout) for debugging.
CONFIGURATION
~/.bigqueryrc
Default configuration file for default project, dataset, format, and per-command flag values. Override its location with --bigqueryrc.
COMMON COMMANDS
query sql
Execute SQL queryls [dataset]
List datasets or tablesshow resource
Show resource detailsmk dataset
Create datasetrm resource
Delete resourceload table source
Load data into tableextract table destination
Export table datacp source destination
Copy table
WORKFLOW
bq query --use_legacy_sql=false \
'SELECT name, count FROM `project.dataset.table` LIMIT 10'
# Create dataset
bq mk --dataset project:mydataset
# Create table
bq mk --table mydataset.mytable schema.json
# Load CSV
bq load --source_format=CSV \
mydataset.mytable \
gs://bucket/data.csv \
name:STRING,age:INTEGER
# Export to GCS
bq extract mydataset.mytable gs://bucket/export.csv
FEATURES
- Interactive and batch queries- Dataset and table management- Data loading from multiple sources- Data export to Cloud Storage- Access control management- Scheduled queries- Data transfer service
CAVEATS
Requires Google Cloud project and authentication. Queries cost based on data processed. Large exports require Cloud Storage. Legacy SQL vs Standard SQL differences. Query costs can accumulate quickly.
HISTORY
bq was released by Google with BigQuery around 2011 as the primary command-line interface for the data warehouse service.