Request a demo

BigQuery · Scripting statement

BigQuery EXPORT DATA

EXPORT DATA writes the result of a query to files in Cloud Storage (CSV, JSON, Avro or Parquet), or to Bigtable, Spanner, Pub/Sub or AlloyDB. The export itself is free; you pay for the query that produces the data, and the URI must contain one * wildcard.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

EXPORT DATA OPTIONS (uri = 'gs://bucket/path/file_*.parquet', format = 'PARQUET') AS SELECT ... runs the query and writes its result as files. The uri must contain exactly one * wildcard in the file name, which BigQuery replaces with a 12-digit sequence number (000000000000, 000000000001, ...): BigQuery decides how many files to write, and their size is not guaranteed. format is required: CSV, JSON (newline-delimited), AVRO or PARQUET. CSV cannot hold nested or repeated columns, and in JSON, INT64 values are written as strings to keep 64-bit precision.

Options control the files: compression (GZIP, DEFLATE, SNAPPY, depending on format), header and field_delimiter for CSV, use_avro_logical_types for Avro, and overwrite. Without overwrite = true the statement fails if the destination is not empty; with it, files with the same names are overwritten but no other files are deleted. An ORDER BY in the query is kept across files in sequence, but avoid LIMIT, which the docs say can make exports slow. The query cannot read INFORMATION_SCHEMA views, system tables or wildcard tables, and the bucket must be in a location compatible with the dataset.

Cost: the export does not bill bytes of its own, but the SELECT is a normal query, billed on demand for the bytes it reads, and Cloud Storage bills the files. That is also why EXPORT DATA is exempt from the 50 TiB per day free extract limit that bq extract jobs on the shared pool have. To export a whole table without a query charge, an extract job (bq extract) is free; EXPORT DATA is the tool when you need filtering, joins, a column subset or a different format per export.

Syntax

EXPORT DATA
[WITH CONNECTION connection_name]
OPTIONS (
  uri = 'gs://bucket/path/prefix_*.ext',
  format = { 'CSV' | 'JSON' | 'AVRO' | 'PARQUET' },
  [overwrite = { true | false },]
  [header = { true | false },]
  [field_delimiter = ',',]
  [compression = 'GZIP' | 'DEFLATE' | 'SNAPPY']
) AS
query_statement

Arguments and return value

ArgumentDescription
uriDestination with exactly one * wildcard in the file name, for example gs://bucket/exports/orders_*.csv. Amazon S3 and Azure Blob Storage URIs work with a connection, from BigQuery Omni.
formatRequired. CSV, JSON, AVRO or PARQUET for files; CLOUD_BIGTABLE, CLOUD_PUBSUB and others for those targets.
overwriteDefault false: the statement fails if the destination is not empty. True overwrites same-named files; it never deletes others.
header / field_delimiterCSV only: write a header row, and choose the separator (default comma).
compressionOptional compression, such as GZIP; the default is uncompressed files.
WITH CONNECTIONOnly for exports to Amazon S3 or Azure Blob Storage through BigQuery Omni; not needed for Google Cloud destinations.

Returns: No result set. Files appear at the destination; the job statistics show the query's bytes processed.

Examples

Export yesterday's orders to CSV with a header

EXPORT DATA OPTIONS (
  uri = 'gs://acme-exports/orders/2026-11-22/orders_*.csv',
  format = 'CSV',
  header = true,
  overwrite = true
) AS
SELECT order_id, customer_id, status, amount, created_at
FROM `project.dataset.orders`
WHERE DATE(created_at) = '2026-11-22'
ORDER BY created_at;

Export compressed Parquet for a data lake

Parquet keeps nested and repeated fields and types; SNAPPY compression keeps files small.

EXPORT DATA OPTIONS (
  uri = 'gs://acme-lake/events/dt=2026-11-22/part_*.parquet',
  format = 'PARQUET',
  compression = 'SNAPPY',
  overwrite = true
) AS
SELECT event_id, user_id, event_name, event_ts, params
FROM `project.dataset.events`
WHERE DATE(event_ts) = '2026-11-22';

One export per day in a script

The URI is built per day with FORMAT, so the statement runs through EXECUTE IMMEDIATE. Each iteration is billed for one day of events.

DECLARE d DATE DEFAULT DATE '2026-11-20';
WHILE d <= DATE '2026-11-22' DO
  EXECUTE IMMEDIATE FORMAT("""
    EXPORT DATA OPTIONS (uri = 'gs://acme-lake/events/dt=%t/part_*.json', format = 'JSON', overwrite = true)
    AS SELECT * FROM `project.dataset.events` WHERE DATE(event_ts) = '%t'
  """, d, d);
  SET d = DATE_ADD(d, INTERVAL 1 DAY);
END WHILE;

Common mistakes

  • Giving a URI without a wildcard, or with two. EXPORT DATA requires exactly one *, even for a small result that fits in one file.
  • Exporting nested or repeated columns to CSV. That fails; use JSON, Avro or Parquet, or flatten the columns with UNNEST and TO_JSON_STRING first.
  • Rerunning an export into a non-empty folder without overwrite = true. The statement fails; with overwrite, leftover files from a previous larger export are kept, so export into a fresh prefix per run.
  • Expecting INT64 values to stay numbers in JSON exports. They are written as strings to keep precision; cast them in the consumer.
  • Adding LIMIT to sample an export. The docs warn that LIMIT can make EXPORT DATA slow; filter with WHERE or TABLESAMPLE instead.

Cost and performance

  • You pay for the query, not the export: filter on the partitioning column and select only needed columns, and the export bills only those bytes on demand. Exporting a full table without transformations is cheaper as an extract job, which does not bill a query.
  • EXPORT DATA runs as a query, so it does not count toward the 50 TiB per day of free extract bytes; on capacity pricing it uses your reservation's slots.

FAQ

How do I export a BigQuery query result to Cloud Storage?

EXPORT DATA OPTIONS (uri = 'gs://bucket/path/file_*.csv', format = 'CSV', header = true) AS SELECT .... The URI needs one * wildcard.

How do I export to a single file?

EXPORT DATA always uses a wildcard URI and may write several files. To get one file, export a table of up to 1 GB with an extract job and a single URI (bq extract), or combine the files afterwards.

Does EXPORT DATA cost money?

The export is not billed, but the SELECT is a normal query billed for the bytes it reads, and Cloud Storage bills the files you store.

Errors you may hit

All BigQuery scripting and data movement · All statements and clauses · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.