Use the ODBC driver for BigQuery
The Open Database Connectivity (ODBC) driver for BigQuery connects your non-Java applications to BigQuery, letting you use BigQuery features with your preferred tooling and infrastructure. To connect Java applications to BigQuery, use the JDBC driver for BigQuery .
The ODBC driver for BigQuery is available under the Apache 2.0 license .
Before you begin
-
Make sure that you're familiar with ODBC drivers and driver managers.
-
Ensure that your operating system meets the following requirements:
Operating system Supported architectures Minimum version and dependencies Windows32-bit (x86), 64-bit (x64) Version: Windows 10, Windows Server 2016 or later
Dependency: Microsoft Visual C++ Redistributable for Visual Studio 2019 or 2022macOS64-bit (x86_64), ARM64 (Apple Silicon) Version: macOS 12 (Monterey) or later
Dependency: An ODBC driver manager (for example, unixODBC ). Ensure you add the installation directory to yourDYLD_LIBRARY_PATH.Linux64-bit (x86_64) Version: Any distribution with glibc 2.27 or later (for example, Ubuntu 20.04 LTS+, Debian 11+)
Dependency: An ODBC Driver Manager (for example, unixODBC ). Ensure that you add the installation directory to yourLD_LIBRARY_PATH. -
Authenticate to BigQuery , and take note of the following information, which is used later when you establish a connection with the ODBC driver for BigQuery. You only need to note the information that corresponds to the authentication method that you use.
Authentication methodAuthentication informationExampleConnection property (to set later)Standard service accountService account key (JSON object)my-sa-keyKeyFilePathWorkload Identity Federation or Workforce Identity FederationAudience property of the external account configuration file//iam.googleapis.com/locations/global/...BYOID_AudienceUrlToken retrieval and environmental information file{"file":"/path/to/file"}BYOID_CredentialSourceUser project (only for workforce pool)my_projectBYOID_PoolUserProjectSTS token typeid_tokenBYOID_SubjectTokenTypeSTS token exchange endpointhttps://sts.googleapis.com/v1/tokenBYOID_TokenUrlApplication Default CredentialsNoneN/AN/A
Install and configure the ODBC driver
You can install and configure the ODBC driver for BigQuery using either a Windows or non-Windows operating system.
Windows
-
Install the driver that corresponds to your application's architecture:
- Download the
ODBCDriverforBigQuery_windows_x86.msifile for 32-bit applications. - Download the
ODBCDriverforBigQuery_windows_x64.msifile for 64-bit applications.
- Download the
-
Create a Data Source Name (DSN) by doing the following:
- From the Windows Startmenu, go to ODBC Data Sources, and select the version that has the same bitness as your client application.
- On the ODBC Data Source Administratorpage, click the Driverstab.
- In the list of installed ODBC drivers, locate ODBC Driver for BigQuery.
- Select either the System DSNtab to create a DSN for all users or the User DSNtab to create a DSN for the current user. System DSNs are generally recommended because some applications load data using different user accounts and might not detect other User DSNs.
- Click Add.
- In the Create New Data Sourcedialog, select ODBC Driver for BigQuery, and then click Finish. The ODBC Driver for BigQuery DSN Setupdialog opens.
- In the Data Source Namefield, enter a name for your DSN.
- Add connection properties. For a full list of properties, see Connection properties .
Non-Windows
-
Install the driver that corresponds to your operating system:
- Download the
ODBCDriverforBigQuery_linux_latest.zipfile for Linux. - Download the
ODBCDriverforBigQuery_macos_latest.tar.gzfile for macOS.
- Download the
-
Extract the contents of the downloaded ZIP or TAR file.
-
Move the contents of the ZIP or TAR file to the directory where you want to install the connector. The ODBC driver for BigQuery shared object path is
INSTALL_DIR /lib/libgoogle_cloud_odbc_bq_driver.so, whereINSTALL_DIRis your installation directory. -
Update your
.inifiles to reflect the new path of the connector.The following example updates the
.inifiles in a Linux system:unzip linux_odbc-driver. VERSION .zip -d linux_odbc-driver. VERSION / cd ./linux_odbc-driver. VERSION export INSTALL_DIR = $( pwd ) export ODBCINI = $ INSTALL_DIR /odbc.ini export ODBCINSTINI = $ INSTALL_DIR /odbcinst.ini export GOOGLEBIGQUERYODBCINI = $ INSTALL_DIR /googlebigqueryodbc.ini
Replace
VERSIONwith the driver version.
Establish a connection
To establish a connection between your application and BigQuery with the ODBC driver for BigQuery, identify your connection string. You can skip this step if you already configured connection properties through your DSN.
The connection string has the following format:
Driver = ODBC Driver for BigQuery ; ProjectId = PROJECT_ID ; OAuthType = AUTH_TYPE ; AUTH_PROPS ; OTHER_PROPS
Replace the following:
-
PROJECT_ID: the ID of your BigQuery project. -
AUTH_TYPE: a number specifying the type of authentication that you used. Select one of the following:-
0: for service account authentication -
3: for Application Default Credential authentication -
4: for Workload Identity Federation or Workforce Identity Federation authentication
-
-
AUTH_PROPS: the authentication information that you noted when you authenticated to BigQuery , listed in theproperty_1=value_1; property_2=value_2;...format—for example,KeyFilePath=my-sa-key, if you authenticated with a service account. -
OTHER_PROPS(optional): additional connection properties for the ODBC driver, listed in theproperty_1=value_1; property_2=value_2;...format. For a full list of connection properties, see Connection properties .
Connection properties
ODBC driver connection properties are configuration parameters that you include in the connection string when you establish a connection to a database. The ODBC driver for BigQuery supports the following connection properties.
AdditionalProjects
ProjectId
property.AllowHtapiForLargeResults
0
AllowLargeResults
QueryDialect
property is set to BIG_QUERY
. If the QueryDialect
property is set
to SQL
, the driver always processes large query results.0
BYOID_AudienceUrl
OAuthMechanism=4
BYOID_CredentialSource
OAuthMechanism=4
BYOID_PoolUserProject
OAuthMechanism=4
and using a Workforce PoolBYOID_SubjectTokenType
-
urn:ietf:params:oauth:token-type:jwt -
urn:ietf:params:oauth:token-type:id_token -
urn:ietf:params:oauth:token-type:saml2 -
urn:ietf:params:aws:token-type:aws4_request
OAuthMechanism=4
BYOID_TokenUrl
https://sts.googleapis.com/v1/token
DefaultDataset
FilterTablesOnDefaultDataset
DefaultDataset
property to enable filtering.FALSE
EnableSession
0
JobCreationMode
-
1: The driver creates jobs for every query (JOB_CREATION_REQUIRED) -
2: The driver executes queries without jobs (JOB_CREATION_OPTIONAL)
2
KeyFilePath
OAuthMechanism=0
KMSKeyName
LargeResultsDataSetId
LargeResultsDatasetExpirationTime
3600000
Location
LogLevel
-
0:OFF -
1:ERROR -
2:WARNING -
3:INFO
0
LogPath
LogFileCount
0
LogFileSize
0
MaxResults
10000
MaxThreads
googlebigqueryodbc.ini
file.8
OAuthMechanism
-
0: Service account authentication -
3: Application Default Credential authentication -
4: Workload Identity Federation or Workforce Identity Federation authentication
ProjectId
ProxyHost
ProxyPort
ProxyPwd
ProxyUid
PrivateServiceConnectUris
-
BIGQUERY=https://bigquery.us-east4.rep.googleapis.com/ -
READ_API=bigquerystorage.us-east4.rep.googleapis.com -
OAUTH2=oauth2.us-east4.rep.googleapis.com
QueryDialect
SQL
for
GoogleSQL (highly recommended) and BIG_QUERY
for
legacy SQL.SQL
QueryProperties
UniverseDomain
googleapis.com
UseQueryCache
true
Data type mapping
When you run queries through the ODBC driver for BigQuery, the following data type mapping occurs:
| GoogleSQL type | ODBC SQL type |
|---|---|
INT64
|
SQL_BIGINT
|
BOOL
|
SQL_BIT
|
DATE
|
SQL_TYPE_DATE
|
FLOAT64
|
SQL_DOUBLE
|
TIME
|
SQL_TYPE_TIME
|
TIMESTAMP
|
SQL_TYPE_TIMESTAMP
|
DATETIME
|
SQL_TYPE_TIMESTAMP
|
BYTES
|
SQL_VARBINARY
|
STRING
|
SQL_VARCHAR
|
ARRAY
|
SQL_VARCHAR
|
STRUCT
|
SQL_VARCHAR
|
INTERVAL
|
SQL_VARCHAR
|
JSON
|
SQL_VARCHAR
|
GEOGRAPHY
|
SQL_VARCHAR
|
RANGE
|
SQL_VARCHAR
|
NUMERIC
|
SQL_NUMERIC
|
BIGNUMERIC
|
SQL_NUMERIC
|
Examples
The following examples demonstrate how to use parameterized queries and multi-statement scripts with the ODBC driver.
Parameterized queries
// 1. Prepare statement std :: string insert_stmt = "INSERT INTO MyTable VALUES (?, ?, ?)" ; status = SQLPrepare ( hstmt , ( SQLCHAR * ) insert_stmt . c_str (), SQL_NTS ); // 2. Bind parameters std :: string str_val = "example_string" ; long long int_val = 12345 ; double float_val = 1.2345 ; // Bind string field status = SQLBindParameter ( hstmt , 1 , SQL_PARAM_INPUT , SQL_C_CHAR , SQL_VARCHAR , 50 , 0 , ( SQLPOINTER ) str_val . c_str (), str_val . size (), NULL ); // Bind integer field status = SQLBindParameter ( hstmt , 2 , SQL_PARAM_INPUT , SQL_C_UBIGINT , SQL_BIGINT , 0 , 0 , & int_val , 0 , NULL ); // Bind float field status = SQLBindParameter ( hstmt , 3 , SQL_PARAM_INPUT , SQL_C_DOUBLE , SQL_DOUBLE , 0 , 0 , & float_val , 0 , NULL ); // 3. Execute statement status = SQLExecute ( hstmt );
Multi-statement scripts
// 1. Prepare and execute the multi-statement script std :: string query = "CREATE OR REPLACE TABLE MyTable (StringField STRING, IntegerField INTEGER); " "INSERT INTO MyTable VALUES ('example', 123); " "SELECT * FROM MyTable;" ; status = SQLExecDirect ( hstmt , ( SQLCHAR * ) query . c_str (), SQL_NTS ); // 2. Process results for each statement using SQLMoreResults do { SQLSMALLINT num_cols ; status = SQLNumResultCols ( hstmt , & num_cols ); if ( num_cols > 0 ) { // This is a result-returning statement (e.g., SELECT) while ( SQLFetch ( hstmt ) == SQL_SUCCESS ) { // Process rows... } } else { // This is a non-result statement (e.g., CREATE, INSERT) SQLLEN row_count ; SQLRowCount ( hstmt , & row_count ); // Process affected rows... } } while ( SQLMoreResults ( hstmt ) == SQL_SUCCESS );
Pricing
You can download the ODBC driver for BigQuery at no cost. However, when you use the driver, standard BigQuery analysis pricing applies.
What's next
- Learn more about the JDBC driver for BigQuery .
- Explore other BigQuery developer tools .

