Files
wehub-resource-sync bb5c75ce05
Component Security Validation / Security Audit (push) Has been cancelled
Deploy to Cloudflare Pages / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:38:58 +08:00

2.0 KiB

BigQuery CLI Usage

The bq command-line tool is used to interact with BigQuery for managing resources and running jobs.

Basic Syntax

bq COMMAND [FLAGS] [ARGUMENTS]

Essential Commands

Dataset Management

  • Create a dataset:

    bq mk --dataset --location=us my_dataset
    
  • List datasets:

    bq ls --project_id my_project
    

Table Management

  • Create a table from a schema file:

    bq mk --table my_dataset.my_table schema.json
    
  • Copy a table within or across datasets:

    bq cp my_dataset.my_table my_other_dataset.my_table_copy
    
  • Create a table snapshot (read-only copy):

    bq cp --snapshot --no_clobber my_dataset.my_table my_other_dataset.my_table_snapshot
    
  • Load data from Cloud Storage (CSV):

    bq load --source_format=CSV my_dataset.my_table gs://my-bucket/data.csv
    
  • Stream data into a table from a newline-delimited JSON file:

    bq insert my_dataset.my_table data.json
    
  • Delete a table:

    bq rm -f my_dataset.my_table
    

Querying Data

  • Run a standard SQL query:

    bq query --use_legacy_sql=false \
    'SELECT count(*) FROM `my_project.my_dataset.my_table`'
    
  • Run a dry run to estimate bytes processed:

    bq query --use_legacy_sql=false --dry_run \
    'SELECT * FROM `my_project.my_dataset.my_table`'
    

Job Management

  • List recent jobs:

    bq ls -j
    
  • Show job details:

    bq show -j job_id
    
  • Cancel a job:

    bq cancel job_id
    

Global Flags

  • --location: Specifies the geographic location for the job or resource.

  • --project_id: Overrides the default project for the command.

  • --format: Changes output format (e.g., prettyjson, sparse, csv).

For the complete BigQuery CLI reference guide, visit: bq command-line tool reference.