> ## Documentation Index
> Fetch the complete documentation index at: https://www.integrate.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ETL: ExecuteBQInsert

> Run a query job in Google BigQuery and write the results to a destination table. Use EXECUTEBQINSERT for in-pipeline BigQuery write operations.

## Description

Starts a query job in Google BigQuery and writes the query results to a destination table.

## Syntax

`ExecuteBQInsert(connection_id, sql_query, configuration_json)`

## Arguments

*connection\_id* (string) - The unique identifier of the connection to use to execute the query. You can find it in the connection's page.

*sql\_query*  - String expression that evaluates to a query that returns a scalar value.

*configuration\_json* - optional string:

```js theme={null}
{
  "destinationTable" : {
 	  "tableId" : string
 	 ,"datasetId" : string
 	 ,"projectId" : string
 	}
 ,"useQueryCache" : boolean
 ,"useLegacySql" : boolean
 ,"jobReference" : { 
           "jobId" : string
          , "projectId" : string  
         }
  ,"writeDisposition": string
  ,"createDisposition": string
  ,"maximumBillingTier" : int
}
```

* destinationTable.tableId - string expression. Specifies the name of the destination table.
* destinationTable.datasetId - optional string expression. Specifies the destination table's dataset. Defaults to connection's default dataset.
* destinationTable.projectId - optional string expression. Specifies the destination table's project. Defaults to connection's default project.
* useQueryCache (optional) - boolean expression. Specifies whether to look for the result in the query cache (default value is true).
* useLegacySql (optional) - boolean expression. Specifies whether to use BigQuery's legacy SQL dialect for the query (default value is false).
* jobReference.jobId (optional) - string expression. Specifies a job id that can be queried afterwards.
* jobReference.projectId (optional) - string expression. Specifies a project to add the job to. If jobId is specified and projectId is empty, the connection's projectId is used.
* writeDisposition (optional) - string expression. The following values are supported:
  * WRITE\_TRUNCATE: If the table already exists, BigQuery overwrites the table data.
  * WRITE\_APPEND: If the table already exists, BigQuery appends the data to the table.
  * WRITE\_EMPTY: If the table already exists and contains data, a 'duplicate' error is returned in the job result.

The default value is WRITE\_EMPTY.

* createDisposition (optional) - string expression. The following values are supported:
  * CREATE\_IF\_NEEDED: If the table does not exist, BigQuery creates the table.
  * CREATE\_NEVER: The table must already exist. If it does not, a 'notFound' error is returned in the job result.

The default value is CREATE\_IF\_NEEDED.

* maximumBillingTier (optional) - Limits the billing tier for this job. Queries that have resource usage beyond this tier will fail. If not specified, defaults to your project default.

## Examples

`ExecuteBQInsert('bq_58', 'SELECT * FROM events_old WHERE ts < \'2017-01-01\';','{"destinationTable" : {"tableId" : "events_stg"}}')`

## Notes

This function only executes in job runtime. When validating a package with variables that use the function or in X-console, the function returns null.

## Return value datatype

The function returns a map with the following keys:

* status - true if the stsatement executed successfully.
* exception - returned exception string if status is false (statement failed)

## Impact of null value

If the connection\_id or sql\_query are null, null is returned.
