BigQuery · Scripting statement
BigQuery LOAD DATA
LOAD DATA loads files from Cloud Storage (CSV, JSON, Avro, Parquet, ORC) into a BigQuery table from SQL: LOAD DATA INTO appends, LOAD DATA OVERWRITE replaces, and a missing table is created. If the load fails, the table is left unchanged.
LOAD DATA INTO table FROM FILES (format = 'PARQUET', uris = ['gs://bucket/path/*.parquet']) is the SQL form of a load job. INTO appends to an existing table and OVERWRITE replaces its contents; if the table doesn't exist, it is created, with partitioning, clustering and options taken from the statement's PARTITION BY, CLUSTER BY and OPTIONS clauses. format and uris are required. Each URI can contain one * wildcard. Without a column list, BigQuery auto-detects the schema; self-describing formats (Avro, Parquet, ORC) carry their own. With a column list, CSV and JSON columns are matched in order and extra file columns are an error unless ignore_unknown_values = true.
PARTITIONS (col = value) writes into exactly one partition, and with OVERWRITE PARTITIONS replaces just that partition: the way to reload one day of an ingestion-time or column-partitioned table without touching the rest. It must start with LOAD DATA INTO, the value must be a literal (for example _PARTITIONTIME = TIMESTAMP '2026-11-22'), and if the data belongs to more than one partition the statement fails. WITH PARTITION COLUMNS reads Hive-style paths (dt=2026-11-22/) into columns, together with hive_partition_uri_prefix. LOAD DATA INTO TEMP TABLE loads into a temporary table of the script or session.
CSV options include skip_leading_rows, field_delimiter, quote, allow_quoted_newlines, allow_jagged_rows, null_marker, encoding and max_bad_records (the number of bad rows to skip before failing). Loads are atomic: if one file is malformed beyond max_bad_records, nothing is written. Each LOAD DATA writes to the table once, so it counts toward the 1,500 table modifications per table per day, like a load job, and one load can write to at most 4,000 partitions. Loading from many small files in one statement with a wildcard is better than one statement per file, which burns through that daily limit.
Syntax
LOAD DATA { INTO | OVERWRITE } [{ TEMP | TEMPORARY } TABLE] [[project.]dataset.]table_name
[(column_name data_type[, ...])]
[[OVERWRITE] PARTITIONS (partition_column = partition_value)]
[PARTITION BY partition_expression]
[CLUSTER BY column[, ...]]
[OPTIONS (table_option = value[, ...])]
FROM FILES (
format = 'CSV' | 'NEWLINE_DELIMITED_JSON' | 'AVRO' | 'PARQUET' | 'ORC',
uris = ['gs://bucket/path/*'][, load_option = value ...]
)
[WITH PARTITION COLUMNS [(column type[, ...])]]
[WITH CONNECTION connection_name]Arguments and return value
| Argument | Description |
|---|---|
INTO / OVERWRITE | INTO appends to an existing table; OVERWRITE replaces its contents. Either creates the table if it doesn't exist. |
column list | Optional schema. Without it BigQuery auto-detects the schema (or reads it from Avro, Parquet and ORC files). |
[OVERWRITE] PARTITIONS (col = value) | Append to, or replace, exactly one partition, given as a literal such as _PARTITIONTIME = TIMESTAMP '2026-11-22'. Requires LOAD DATA INTO; not __NULL__ or __UNPARTITIONED__. |
FROM FILES (...) | Load options. format and uris are required; CSV options include skip_leading_rows, field_delimiter, null_marker, max_bad_records, allow_quoted_newlines. |
WITH PARTITION COLUMNS | Read Hive-partitioned paths into columns; use with hive_partition_uri_prefix. |
WITH CONNECTION | A connection for sources outside Google Cloud, such as Amazon S3 or Azure Blob Storage through BigQuery Omni. |
Returns: No result set. The table (or partition) contains the loaded rows; on failure it is unchanged.
Examples
Append Parquet files into a partitioned table
LOAD DATA INTO `project.dataset.events`
PARTITION BY DATE(event_ts)
CLUSTER BY event_name
FROM FILES (
format = 'PARQUET',
uris = ['gs://acme-landing/events/2026-11-22/*.parquet']
);Load a CSV export with an explicit schema
Skips the header row, treats empty strings as NULL and tolerates up to 10 malformed rows before failing.
LOAD DATA INTO `project.dataset.invoices`
(
invoice_id STRING,
customer_id STRING,
amount NUMERIC,
issued_on DATE
)
FROM FILES (
format = 'CSV',
uris = ['gs://acme-landing/billing/invoices_2026_11_*.csv'],
skip_leading_rows = 1,
null_marker = '',
max_bad_records = 10
);Reload one day without touching the rest
Replaces only the 2026-11-22 partition of the ingestion-time partitioned raw_webhooks table; every other day is untouched. A failed load leaves the old partition in place.
LOAD DATA INTO `project.dataset.raw_webhooks`
OVERWRITE PARTITIONS (_PARTITIONTIME = TIMESTAMP '2026-11-22')
FROM FILES (
format = 'NEWLINE_DELIMITED_JSON',
uris = ['gs://acme-landing/webhooks/2026-11-22/*.json']
);Load Hive-partitioned files and keep the path as a column
LOAD DATA INTO `project.dataset.clicks`
FROM FILES (
format = 'PARQUET',
uris = ['gs://acme-lake/clicks/*'],
hive_partition_uri_prefix = 'gs://acme-lake/clicks'
)
WITH PARTITION COLUMNS (dt DATE);Common mistakes
- Running LOAD DATA OVERWRITE when you meant to replace one day. It replaces the whole table; use
LOAD DATA INTO ... OVERWRITE PARTITIONS (...). - Relying on schema auto-detection for CSV in production. Types are inferred from a sample, so a column of IDs can become INT64 one day and fail the next; declare the column list.
- Loading one small file per statement. Each LOAD DATA is a table modification, and a table allows 1,500 per day; load many files with one wildcard URI.
- Mismatched schemas between files and table. A type or column mismatch fails with Provided schema does not match table; bad CSV rows beyond
max_bad_recordsfail with CSV table encountered too many errors. - Loading from a bucket in another location. The dataset and the Cloud Storage bucket must be in compatible locations.
Cost and performance
- Load jobs on the shared slot pool are a free operation; you pay for the stored data afterwards. LOAD DATA runs as a query job, so check the first runs' bytes billed in INFORMATION_SCHEMA.JOBS if exact cost matters.
- Avro and Parquet files can be read in parallel even when compressed, while gzipped CSV and JSON files cannot, so large recurring loads go faster from Avro or Parquet, or from uncompressed CSV.
- A load that writes many partitions counts each partition modification; one statement can affect at most 4,000 partitions, and a column-partitioned table allows 30,000 partition modifications per day.
FAQ
How do I load a CSV from Cloud Storage into BigQuery with SQL?
LOAD DATA INTO dataset.t FROM FILES (format = 'CSV', uris = ['gs://bucket/file.csv'], skip_leading_rows = 1). Add a column list to fix the schema instead of auto-detecting it.
What is the difference between LOAD DATA INTO and LOAD DATA OVERWRITE?
INTO appends rows to the table; OVERWRITE replaces all of its rows. To replace a single partition, use INTO with OVERWRITE PARTITIONS (...).
What happens if LOAD DATA fails halfway?
Nothing is written. The table stays as it was before the statement, so you can fix the files and rerun it.
Related
Errors you may hit
More scripting and data movement
All BigQuery scripting and data movement · All statements and clauses · BigQuery error messages
