Importing Google Sheets into BigQuery

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified
Search for a command to run...

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified
No comments yet. Be the first to comment.
Hands-on guides to data tooling, infrastructure, and operations — scheduling, pipelines, access control, and the engineering behind data workflows.
Maybe save a bit on that next expensive laptop upgrade? Over the weekend, I worked on some small personal projects and decided to try out remote development using SSH and Visual Studio Code. I have an 18 GB M3 Pro MBP, which is acceptable, but it’s n...
Here's a useful Dataform concept: pre_operations and post_operations. As the name implies, these represent a set of actions that run before and after the main operation (table, view, or SQL operations

BigQuery has always been a SQL engine for tabular data. Object tables add an interesting twist to that. Instead of rows containing values, an object table gives you one row per file — pointing at da

Query your data lake with warehouse-grade security and performance — without moving a single file.

Ever run a heavy BigQuery SQL query, processed gigabytes of data — and then accidentally closed the tab or forgot to save the results? 😬 Don't re-run it. Your results are still there. BigQuery automa

You can use query parameters in BigQuery hashtag#SQL (now in the console as well!) — but how are they different from variables, and when should you use each? Both parameters and variables act as place

Spreadsheets are a central part of a modern workplace. Pretty much every office workplace uses one. It's also quite used for personal use cases. One such product is Google Sheets.
I use it for many things - organizing finance, planning travel itineraries, collecting data and expenses.
Today I want to illustrate how we can integrate data from Google Sheets to BigQuery.
In BigQuery, a Google Sheets page can be represented as an external table - a type of table where the data is stored outside of BigQuery.
I've seen them used for holding static (seed) data and mapping tables, an improvised Master Data Management of sorts, allowing analysts to edit data as business realities change.
Security - who can view and edit Sheets
History - how do you handle change in sheets? Do you need snapshots?
Recovery - what if someone deletes data from the worksheet?
Let's see an example of how to set it up.

We start by adding a new data source.

We pick the Google Drive as the source.

We provide the necessary configuration:
Google Sheets URL
Destination Table: project, dataset, table name
We provide the schema: column names and types
We provided the number of header rows to be skipped

After we hit Create Table the external table is created. We can verify that the data has been properly created.

We might need to see the DDL (data definition language) statement for a table. This can be achieved using one of the INFORMATION_SCHEMA tables.
Using the query below you can see how the (external in our case) table is defined.
SELECT
table_name, ddl
FROM
learning.INFORMATION_SCHEMA.TABLES;

CREATE EXTERNAL TABLE `learning.example_table`
(
FirstName STRING OPTIONS(description="First Name"),
LastName STRING OPTIONS(description="Last Name"),
City STRING OPTIONS(description="City"),
Country STRING OPTIONS(description="Country")
)
OPTIONS(
sheet_range="A1:D4",
skip_leading_rows=1,
format="GOOGLE_SHEETS",
uris=["https://docs.google.com/spreadsheets/d/**edited_text**/edit#gid=0"]
);
Thanks for reading and keep enjoying SQL!
Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.