LinuxCommandLibrary

bq

Google BigQuery command-line interface

TLDR

Query data

$ bq query ["SELECT * FROM dataset.table LIMIT 10"]
copy
List datasets
$ bq ls
copy
Show table schema
$ bq show [dataset.table]
copy
Load data
$ bq load --source_format=CSV [dataset.table] [data.csv] [schema.json]
copy
Extract data
$ bq extract [dataset.table] gs://[bucket/file.csv]
copy

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 query
ls [dataset]
List datasets or tables
show resource
Show resource details
mk dataset
Create dataset
rm resource
Delete resource
load table source
Load data into table
extract table destination
Export table data
cp source destination
Copy table

WORKFLOW

$ # Run query
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
copy

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.

SEE ALSO

gcloud(1), gsutil(1), psql(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community