Export BigQuery table to Google Cloud Storage

A code example for how to write BigQuery SQL to export a table to Google Cloud Storage in csv and parquet file formats.

Parquet

-- Export a table in BigQuery to Google Cloud Storage in parquet file format

EXPORT DATA OPTIONS(
  uri='gs://a_google_cloud_storage_bucket/a_folder/prefix_for_the_saved_file-*.parquet',
  format='PARQUET',
  overwrite=true
) AS 
SELECT 
	* 
FROM a-project.a-dataset.table_to_export_to_gcs_in_parquet_format;

CSV

-- Export a table in BigQuery to Google Cloud Storage in csv file format

EXPORT DATA OPTIONS(
  uri='gs://a_google_cloud_storage_bucket/a_folder/prefix_for_the_saved_file-*.csv',
  format='CSV', 
  overwrite=true, 
  header=true, 
  field_delimiter=','
) AS 
SELECT 
	* 
FROM a-project.a-dataset.table_to_export_to_gcs_in_csv_format;

Send a Comment

Your email address will not be published.