Load statements in GoogleSQL
LOAD DATA statement
Loads data from one or more files into a table. The statement can create a newtable, append data into an existing table or partition, or overwrite an existingtable or partition. If theLOAD DATA statement fails, the table into which youare loading data remains unchanged.
Syntax
LOAD DATA {OVERWRITE|INTO} [{TEMP|TEMPORARY} TABLE][[project_name.]dataset_name.]table_name[( column_list)][[OVERWRITE] PARTITIONS (partition_column_name=partition_value)][PARTITION BYpartition_expression][CLUSTER BY clustering_column_list][OPTIONS (table_option_list)]FROM FILES(load_option_list)[WITH PARTITION COLUMNS [(partition_column_list)]][WITH CONNECTION connection_name]column_list:column[, ...]partition_column_list: partition_column_name, partition_column_type[, ...]Arguments
INTO: If a table with this name already exists, the statement appends datato the table. You must useINTOinstead ofOVERWRITEif your statementincludes thePARTITIONSclause.OVERWRITE: If a table with this name already exists, the statementoverwrites the table.{TEMP|TEMPORARY} TABLE: Use this clause to create or write to a temporarytable.project_name: The name of the project for the table. The valuedefaults to the project that runs this DDL query.dataset_name: The name of the dataset for the table.table_name: The name of the table.column_list: Contains the table's schema information as a list of tablecolumns. For more information about table schemas, seeSpecifying a schema. If you don't specify a schema,BigQuery usesschema auto-detection to infer the schema.When you load hive-partitioned data into a new table or overwrite an existingtable, then that tableschema contains the hive-partitioned columns and the columns in the
column_list.If you append hive-partitioned data to an existing table, then thehive-partitioned columns and
column_listcan be a subset of the existingcolumns. If the combined list of columns in not a subset of the existingcolumns, then the following rules apply:If your data is self-describing, such as ORC, PARQUET, or AVRO, thencolumns in the source file that are omitted from the
column_listare ignored. Columns in thecolumn_listthat don't exist in the sourcefile are written withNULLvalues. If a column is in thecolumn_listand the source file, then their types must match.If your data is not self-describing, such as CSV or JSON, then columnsin the source file that are omitted from the
column_listare onlyignored if you setignore_unknown_valuestoTRUE. Otherwise thisstatement returns an error. You can't listcolumns in thecolumn_listthat don't exist in the source file.
[OVERWRITE] PARTITIONS: Use this clause to write to oroverwrite exactly one partition. When you use this clause, the statementmust begin withLOAD DATA INTO.partition_column_name: The name of the partitioned column to write to.If you use both thePARTITIONSand thePARTITION BYclauses, then thecolumn names must match.partition_value: Thepartition_idof the partition to append oroverwrite.To find thepartition_idvalues of a table, query theINFORMATION_SCHEMA.PARTITIONSview.You can't set thepartition_valueto__NULL__or__UNPARTITIONED__.You can only append to or overwrite one partition. If your data containsvalues that belong to multiple partitions, then the statementfails with an error. Thispartition_valuemust be literal value.partition_expression: Specifies the table partitioning when creating anew table.clustering_column_list: Specifies table clustering when creating a newtable. The value is a comma-separated list of column names, with up to fourcolumns.table_option_list: Specifies options for creatingthe table. If you include this clause and the table already exists, then theoptions must match the existing table specification.partition_column_list: A list of external partitioning columns.connection_name: The connection name that is used to read the sourcefiles from anexternal data source.load_option_list: Specifies options for loading thedata.
If no table exists with the specified name, then the statement creates a newtable. If a table already exists with the specified name, then the behaviordepends on theINTO orOVERWRITE keyword. TheINTO keyword appends thedata to the table, and theOVERWRITE keyword overwrites the table.
If your external data uses ahive-partitioned layout,then include theWITH PARTITION COLUMNS clause. If you include theWITHPARTITION COLUMNS clause withoutpartition_column_list, thenBigQuery infers the partitioning from the data layout. If youinclude bothcolumn_list andWITH PARTITION COLUMNS, thenpartition_column_list is required.
You can't use theLOAD DATA statement to load data into a temporary table.
column
(column_name column_schema[, ...]) contains the table'sschema information in a comma-separated list.
ARRAY orSTRUCT elements.column:=column_namecolumn_schemacolumn_schema:={simple_type|STRUCT<field_list>|ARRAY<array_element_schema>}[PRIMARYKEYNOTENFORCED|REFERENCEStable_name(column_name)NOTENFORCED][DEFAULTdefault_expression|GENERATEDALWAYSAS(generation_expression)STOREDOPTIONS(generation_option_list)][NOTNULL][OPTIONS(column_option_list)]simple_type:={data_type|STRINGCOLLATEcollate_specification}field_list:=field_namecolumn_schema[,...]array_element_schema:={simple_type|STRUCT<field_list>}[NOTNULL]
column_nameis the name of the column.A column name:- Must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_)
- Must start with a letter or underscore
- Can be up to 300 characters
column_schema: Similar to adata type, but supports anoptionalNOT NULLconstraint for types other thanARRAY.column_schemaalso supports options on top-level columns andSTRUCTfields.column_schemacan be used only in the column definition list ofCREATE TABLEstatements. It cannot be used as a type in expressions.simple_type: Anysupported data typeaside fromSTRUCTandARRAY.If
simple_typeis aSTRING, it supports an additional clause forcollation,which defines how a resultingSTRINGcan be compared and sorted.The syntax looks like this:STRINGCOLLATEcollate_specificationIf you have
DEFAULT COLLATE collate_specificationassigned to the table,the collation specification for a column overrides the specification for thetable.default_expression: Thedefault valueassigned to the column. You cannot specifyDEFAULTifGENERATED ALWAYS ASis specified.generation_expression: (Preview)An expression for an automatically generated embedding column.Setting this field enablesautonomous embedding generationon the table. The onlysupportedgeneration_expressionsyntax is a call to theAI.EMBEDfunction.- You can't specify
GENERATED ALWAYS ASifDEFAULTis specified. - The
connection_idargument toAI.EMBEDis required when used in ageneration expression. - The type of the column must be
STRUCT<result ARRAY<FLOAT64>, status STRING>.
- You can't specify
generation_option_list: The options for a generated column.The only supported option isasynchronous = TRUE.field_list: Represents the fields in a struct.field_name: The name of the struct field. Struct field names have thesame restrictions as column names.NOT NULL: When theNOT NULLconstraint is present for a column or field,the column or field is created withREQUIREDmode. Conversely, when theNOT NULLconstraint is absent, the column or field is created withNULLABLEmode.Columns and fields of
ARRAYtype do not support theNOT NULLmodifier. Forexample, acolumn_schemaofARRAY<INT64> NOT NULLis invalid, sinceARRAYcolumns haveREPEATEDmode and can be empty but cannot beNULL.An array element in a table can never beNULL, regardless of whether theNOT NULLconstraint is specified. For example,ARRAY<INT64>is equivalenttoARRAY<INT64 NOT NULL>.The
NOT NULLattribute of a table'scolumn_schemadoes not propagatethrough queries over the table. If tableTcontains a column declared asx INT64 NOT NULL, for example,CREATE TABLE dataset.newtable AS SELECT x FROM Tcreates a table nameddataset.newtablein whichxisNULLABLE.
column_option_list
Specify a column option list in the following format:
NAME=VALUE, ...
NAME andVALUE must be one of the following combinations:
NAME | VALUE | Details |
|---|---|---|
description |
| Example: This property is equivalent to theschema.fields[].description table resource property. |
rounding_mode |
| Example: This specifies therounding mode that's used for values written to a
This property is equivalent to the |
data_policies | ARRAY<STRING> | Applies adata policy to a column in a table (Preview). Example: The Example: |
VALUE is a constant expression containing only literals, query parameters,and scalar functions.
The constant expressioncannot contain:
- A reference to a table
- Subqueries or SQL statements such as
SELECT,CREATE, orUPDATE - User-defined functions, aggregate functions, or analytic functions
- The following scalar functions:
ARRAY_TO_STRINGREPLACEREGEXP_REPLACERANDFORMATLPADRPADREPEATSESSION_USERGENERATE_ARRAYGENERATE_DATE_ARRAY
Setting theVALUE replaces the existing value of that option for the column, ifthere was one. Setting theVALUE toNULL clears the column's value for thatoption.
partition_expression
PARTITION BY is an optional clause that controlstable andvector index partitioning.partition_expression is an expression that determines how to partition thetable or vector index. The partition expression can contain the followingvalues:
_PARTITIONDATE. Partition by ingestion time with daily partitions. Thissyntax cannot be used with theAS query_statementclause.DATE(_PARTITIONTIME). Equivalent to_PARTITIONDATE. This syntax cannot beused with theAS query_statementclause.<date_column>. Partition by aDATEcolumn with daily partitions.DATE({ <timestamp_column> | <datetime_column> }). Partition by aTIMESTAMPorDATETIMEcolumn with daily partitions.DATETIME_TRUNC(<datetime_column>, { DAY | HOUR | MONTH | YEAR }). Partitionby aDATETIMEcolumn with the specified partitioning type.TIMESTAMP_TRUNC(<timestamp_column>, { DAY | HOUR | MONTH | YEAR }).Partition by aTIMESTAMPcolumn with the specified partitioning type.TIMESTAMP_TRUNC(_PARTITIONTIME, { DAY | HOUR | MONTH | YEAR }). Partitionby ingestion time with the specified partitioning type. This syntax cannot beused with theAS query_statementclause.DATE_TRUNC(<date_column>, { MONTH | YEAR }). Partition by aDATEcolumnwith the specified partitioning type.RANGE_BUCKET(<int64_column>, GENERATE_ARRAY(<start>, <end>[, <interval>])).Partition by an integer column with the specified range, where:startis the start of range partitioning, inclusive.endis the end of range partitioning, exclusive.intervalis the width of each range within the partition. Defaults to 1.
table_option_list
The option list lets you set table options such as alabel and an expiration time. You can include multipleoptions using a comma-separated list.
Specify a table option list in the following format:
NAME=VALUE, ...
NAME andVALUE must be one of the following combinations:
NAME | VALUE | Details |
|---|---|---|
expiration_timestamp | TIMESTAMP | Example: This property is equivalent to theexpirationTime table resource property. |
partition_expiration_days |
| Example: Sets the partition expiration in days. For more information, see Set the partition expiration. By default, partitions don't expire. This property is equivalent to thetimePartitioning.expirationMs table resource property but uses days instead of milliseconds. One day is equivalent to 86400000 milliseconds, or 24 hours. This property can only be set if the table is partitioned. |
require_partition_filter |
| Example: Specifies whether queries on this table must include a a predicate filter that filters on the partitioning column. For more information, see Set partition filter requirements. The default value is This property is equivalent to thetimePartitioning.requirePartitionFilter table resource property. This property can only be set if the table is partitioned. |
friendly_name |
| Example: This property is equivalent to thefriendlyName table resource property. |
description |
| Example: This property is equivalent to thedescription table resource property. |
labels |
| Example: This property is equivalent to thelabels table resource property. |
default_rounding_mode |
| Example: This specifies the defaultrounding mode that's used for values written to any new
This property is equivalent to the |
enable_change_history |
| Inpreview. Example: Set this property to |
max_staleness |
| Example: The maximum interval behind the current time where it's acceptable to read stale data. For example, withchange data capture, when this option is set, the table copy operation is denied if data is more stale than the
|
enable_fine_grained_mutations |
| Inpreview. Example: Set this property to |
storage_uri |
| Inpreview. Example: A fully qualified location prefix for the external folder where data is stored. Supports Required formanaged tables. |
file_format |
| Inpreview. Example: The open-source file format in which the table data is stored. Only Required formanaged tables. The default is |
table_format |
| Inpreview. Example: The open table format in which metadata-only snapshots are stored. Only Required formanaged tables. The default is |
tags | <ARRAY<STRUCT<STRING, STRING>>> | An array of IAM tags for the table, expressed as key-value pairs. The key should be thenamespaced key name, and the value should be theshort name. |
VALUE is a constant expression containing only literals, query parameters,and scalar functions.
The constant expressioncannot contain:
- A reference to a table
- Subqueries or SQL statements such as
SELECT,CREATE, orUPDATE - User-defined functions, aggregate functions, or analytic functions
- The following scalar functions:
ARRAY_TO_STRINGREPLACEREGEXP_REPLACERANDFORMATLPADRPADREPEATSESSION_USERGENERATE_ARRAYGENERATE_DATE_ARRAY
load_option_list
Specifies options for loading data from external files. Theformat andurisoptions are required. Specify the option list in the following format:NAME=VALUE, ...
| Options | |
|---|---|
allow_jagged_rows |
If Applies to CSV data. |
allow_quoted_newlines |
If Applies to CSV data. |
bigtable_options |
Only required when creating a Bigtable external table. Specifies the schema of the Bigtable external table in JSON format. For a list of Bigtable table definition options, see |
column_name_character_map |
Defines the scope of supported column name characters and the handling behavior of unsupported characters. The default setting is Supported values include:
Applies to CSV and Parquet data. |
compression |
The compression type of the data source. Supported values include: Applies to CSV and JSON data. |
decimal_target_types |
Determines how to convert a Example: |
enable_list_inference |
If Applies to Parquet data. |
enable_logical_types |
If Applies to Avro data. |
encoding |
The character encoding of the data. Supported values include: Applies to CSV data. |
enum_as_string |
If Applies to Parquet data. |
field_delimiter |
The separator for fields in a CSV file. Applies to CSV data. |
format |
The format of the external data. Supported values for Supported values for The value |
hive_partition_uri_prefix |
A common prefix for all source URIs before the partition key encoding begins. Applies only to hive-partitioned external tables. Applies to Avro, CSV, JSON, Parquet, and ORC data. Example: |
file_set_spec_type |
Specifies how to interpret source URIs for load jobs and external tables. Supported values include:
For example, if you have a source URI of |
ignore_unknown_values |
If Applies to CSV and JSON data. |
json_extension |
For JSON data, indicates a particular JSON interchange format. If not specified, BigQuery reads the data as generic JSON records. Supported values include: |
max_bad_records |
The maximum number of bad records to ignore when reading the data. Applies to: CSV, JSON, and Google Sheets data. |
max_staleness |
Applicable forBigLake tables andobject tables. Specifies whether cached metadata is used by operations against the table, and how fresh the cached metadata must be in order for the operation to use it. To disable metadata caching, specify 0. This is the default. To enable metadata caching, specify aninterval literal value between 30 minutes and 7 days. For example, specify |
null_marker |
The string that represents Applies to CSV data. |
null_markers |
(Preview) The list of strings that represent This option cannot be used with Applies to CSV data. |
object_metadata |
Only required when creating anobject table. Set the value of this option to |
preserve_ascii_control_characters |
If Applies to CSV data. |
quote |
The string used to quote data sections in a CSV file. If your data contains quoted newline characters, also set the Applies to CSV data. |
skip_leading_rows |
The number of rows at the top of a file to skip when reading the data. Applies to CSV and Google Sheets data. |
source_column_match |
(Preview) This controls the strategy used to match loaded columns to the schema. If this value is unspecified, then the default is based on how the schema is provided. If autodetect is enabled, then the default behavior is to match columns by name. Otherwise, the default is to match columns by position. This is done to keep the behavior backward-compatible. Supported values include:
|
tags | <ARRAY<STRUCT<STRING, STRING>>>An array of IAM tags for the table, expressed as key-value pairs. The key should be thenamespaced key name, and the value should be theshort name. |
time_zone |
(Preview) Default time zone that will apply when parsing timestamp values that have no specific time zone. Checkvalid time zone names. If this value is not present, the timestamp values without specific time zone is parsed using default time zone UTC. Applies to CSV and JSON data. |
date_format |
(Preview) Format elements that define how the DATE values are formatted in the input files (for example, If this value is present, this format is the only compatible DATE format.Schema autodetection will also decide DATE column type based on this format instead of the existing format. If this value is not present, the DATE field is parsed with thedefault formats. Applies to CSV and JSON data. |
datetime_format |
(Preview) Format elements that define how the DATETIME values are formatted in the input files (for example, If this value is present, this format is the only compatible DATETIME format.Schema autodetection will also decide DATETIME column type based on this format instead of the existing format. If this value is not present, the DATETIME field is parsed with thedefault formats. Applies to CSV and JSON data. |
time_format |
(Preview) Format elements that define how the TIME values are formatted in the input files (for example, If this value is present, this format is the only compatible TIME format.Schema autodetection will also decide TIME column type based on this format instead of the existing format. If this value is not present, the TIME field is parsed with thedefault formats. Applies to CSV and JSON data. |
timestamp_format |
(Preview) Format elements that define how the TIMESTAMP values are formatted in the input files (for example, If this value is present, this format is the only compatible TIMESTAMP format.Schema autodetection will also decide TIMESTAMP column type based on this format instead of the existing format. If this value is not present, the TIMESTAMP field is parsed with thedefault formats. Applies to CSV and JSON data. |
uris | For external tables, including object tables, that aren't Bigtable tables:
An array of fully qualified URIs for the external data locations. Each URI can contain one asterisk ( The following examples show valid
For Bigtable tables:
The URI identifying the Bigtable table to use as a data source. You can only specify one Bigtable URI. Example: For more information on constructing a Bigtable URI, seeRetrieve the Bigtable URI. |
Examples
The following examples show common use cases for theLOAD DATA statement.
Load data into a table
The following example loads an Avro file into a table. Avro is aself-describing format, so BigQuery infers the schema.
LOADDATAINTOmydataset.table1FROMFILES(format='AVRO',uris=['gs://bucket/path/file.avro'])
The following example loads two CSV files into a table, using schemaautodetection.
LOADDATAINTOmydataset.table1FROMFILES(format='CSV',uris=['gs://bucket/path/file1.csv','gs://bucket/path/file2.csv'])
Load data using a schema
The following example loads a CSV file into a table, using a specified tableschema.
LOADDATAINTOmydataset.table1(xINT64,ySTRING)FROMFILES(skip_leading_rows=1,format='CSV',uris=['gs://bucket/path/file.csv'])
Set options when creating a new table
The following example creates a new table with a description and an expirationtime.
LOADDATAINTOmydataset.table1OPTIONS(description="my table",expiration_timestamp="2025-01-01 00:00:00 UTC")FROMFILES(format='AVRO',uris=['gs://bucket/path/file.avro'])
Overwrite an existing table
The following example overwrites an existing table.
LOADDATAOVERWRITEmydataset.table1FROMFILES(format='AVRO',uris=['gs://bucket/path/file.avro'])
Load data into a temporary table
The following example loads an Avro file into a temporary table.
LOADDATAINTOTEMPTABLEmydataset.table1FROMFILES(format='AVRO',uris=['gs://bucket/path/file.avro'])
Specify table partitioning and clustering
The following example creates a table that is partitioned by thetransaction_date field and clustered by thecustomer_id field. It alsoconfigures the partitions to expire after three days.
LOADDATAINTOmydataset.table1PARTITIONBYtransaction_dateCLUSTERBYcustomer_idOPTIONS(partition_expiration_days=3)FROMFILES(format='AVRO',uris=['gs://bucket/path/file.avro'])
Load data into a partition
The following example loads data into a selected partition of an ingestion-timepartitioned table:
LOADDATAINTOmydataset.table1PARTITIONS(_PARTITIONTIME=TIMESTAMP'2016-01-01')PARTITIONBY_PARTITIONTIMEFROMFILES(format='AVRO',uris=['gs://bucket/path/file.avro'])
Load a file that is externally partitioned
The following example loads a set of external files that use ahive partitioninglayout.
LOADDATAINTOmydataset.table1FROMFILES(format='AVRO',uris=['gs://bucket/path/*'],hive_partition_uri_prefix='gs://bucket/path')WITHPARTITIONCOLUMNS(field_1STRING,-- column order must match the external pathfield_2INT64)
The following example infers the partitioning layout:
LOADDATAINTOmydataset.table1FROMFILES(format='AVRO',uris=['gs://bucket/path/*'],hive_partition_uri_prefix='gs://bucket/path')WITHPARTITIONCOLUMNS
If you include bothcolumn_list andWITH PARTITION COLUMNS, then you mustexplicitly list the partitioning columns. For example, the following queryreturns an error:
-- This query returns an error.LOADDATAINTOmydataset.table1(xINT64,-- column_list is given but the partition column list is missingySTRING)FROMFILES(format='AVRO',uris=['gs://bucket/path/*'],hive_partition_uri_prefix='gs://bucket/path')WITHPARTITIONCOLUMNS
Load data with cross-cloud transfer
Example 1
The following example loads a parquet file namedsample.parquet from an Amazon S3bucket into thetest_parquet table with an auto-detect schema:
LOADDATAINTOmydataset.testparquetFROMFILES(uris=['s3://test-bucket/sample.parquet'],format='PARQUET')WITHCONNECTION`aws-us-east-1.test-connection`
Example 2
The following example loads a CSV file with the prefixsampled* from yourBlob Storage into thetest_csv table with predefined column partitioning by time:
LOADDATAINTOmydataset.test_csv(NumberINT64,NameSTRING,TimeDATE)PARTITIONBYTimeFROMFILES(format='CSV',uris=['azure://test.blob.core.windows.net/container/sampled*'],skip_leading_rows=1)WITHCONNECTION`azure-eastus2.test-connection`
Example 3
The following example overwrites the existing tabletest_parquet withdata from a file namedsample.parquet with an auto-detect schema:
LOADDATAOVERWRITEmydataset.testparquetFROMFILES(uris=['s3://test-bucket/sample.parquet'],format='PARQUET')WITHCONNECTION`aws-us-east-1.test-connection`
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.