Connecting data from Google Sheets to BigQuery¶
In this tutorial, we'll show you how to read a Google Sheet from BigQuery.
Want to master BigQuery?
Check out our free BigQuery practice problems with solutions
At the time of writing, Google supports two directions of data flow:
- from BigQuery to Google Sheets
- from Google Sheets to BigQuery
There is no two-way connection.
This tutorial is about the latter, a connection that moves data from Google Sheets to BigQuery. Here's a gif that shows everything in about 90 seconds.
This guide was created following these docs.
Steps¶
- Create a Google Sheet
- In the BigQuery console, click Add Data
- Select Drive as the data source
- Set the Drive URI as the URL of your Google Sheet
- Input the sheet range (hover over the icon for details)
- Choose your dataset and table name
- Enter the table schema. It should match the sheet!
- Under Advanced Options set Header rows to skip equal to 1
- CREATE TABLE
Access Denied: Permission denied while getting Drive credentials
If you get an error like this, it means that the account creating the connection in BigQuery does not have permission to the google sheet. To resolve this,
- Head over to the IAM dashboard.
- Copy the email address of the account responsible for creating tables in BigQuery
- Head over to your Google Sheet
-
Click the green Share button in the top right and paste the email address you just copied
Now you should be able to create the table in BigQuery.
Notes¶
- Your freshly created "table" won't appear in the explorer pane until you refresh the window.
- You cannot preview the table like you can with normal BigQuery tables. To see the data, you need to query it:
select * from mydataset.mysheet limit 1000
. - Your "table" is similar to a view. Every time you query the table, it fetches the data from your google sheet. It doesn't know when your sheet has been edited (and therefore doesn't use caching). It just grabs fresh data every time you use it.