bq
Google BigQuery command-line interface
TLDR
Query data
SYNOPSIS
bq [options] command
DESCRIPTION
bq is the command-line interface for Google BigQuery. It enables querying massive datasets, managing tables and datasets, loading data, and controlling access through a unified interface.
The tool provides programmatic access to BigQuery's data warehouse capabilities.
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 standard SQL (recommended)
CONFIGURATION
~/.bigqueryrc
User configuration file for default project, dataset, format, and query settings.
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.
