Google Sheets
Read and write Google Sheets with SQL. Join a spreadsheet to your data or send query results back to a sheet.
Install
INSTALL gsheets FROM community;
LOAD gsheets;
Connect your account
Run this in your local Haybarn session to sign in with Google. You need access to the spreadsheet you want to query.
CREATE SECRET (TYPE gsheet);
For a pipeline or application, the extension also supports access tokens and service account keys. Follow the developer’s authentication instructions.
gsheet · default provider oauthArguments & returns
read_gsheet
Table functionSignature
Arguments
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
VARCHAR
|
Mode Positional | Description Spreadsheet URL or spreadsheet ID. |
Argument
all_varchar
|
Type
BOOLEAN
|
Mode Named | Description Read all values in as varchar, skipping type inference |
Argument
range
|
Type
VARCHAR
|
Mode Named | Description Read a spreadsheet using a specific range or using A1 notation or from range in URL |
Argument
sheet
|
Type
VARCHAR
|
Mode Named | Description Read a sheet other than the first sheet using the sheet name |
Argument
header
|
Type
BOOLEAN
|
Mode Named | Description Read a spreadsheet with no header row |
Returns
Columns are determined from the selected sheet or range. Use all_varchar to read all values as text.
Dynamic schema. The output columns are determined at bind time and vary per call, so they aren't listed here.
Signatures from Haybarn 1.5.5; explanations from the developer documentation.
Read a spreadsheet
Use the full spreadsheet URL or its ID. These examples use the spreadsheet from the developer’s documentation; substitute one your account can access.
-- Read a spreadsheet by full URL
FROM read_gsheet('https://docs.google.com/spreadsheets/d/11QdEasMWbETbFVxry-SsD8jVcdYIT1zBQszcF84MdE8/edit');
-- Read a spreadsheet with no header row
SELECT * FROM read_gsheet('11QdEasMWbETbFVxry-SsD8jVcdYIT1zBQszcF84MdE8', header=false);
-- Read a spreadsheet using a specific range
SELECT * FROM read_gsheet('11QdEasMWbETbFVxry-SsD8jVcdYIT1zBQszcF84MdE8', sheet='Sheet1', range='B1:C7');
-- or using A1 notation
SELECT * FROM read_gsheet('11QdEasMWbETbFVxry-SsD8jVcdYIT1zBQszcF84MdE8', sheet='Sheet1!B1:C7');
-- or from range in URL
SELECT * FROM read_gsheet('https://docs.google.com/spreadsheets/d/11QdEasMWbETbFVxry-SsD8jVcdYIT1zBQszcF84MdE8/edit?gid=0#gid=0&range=B1:C7');
Write query results to a sheet
The extension also supports COPY … TO with FORMAT gsheet. The destination spreadsheet must already exist. Replace <table_name> and the destination ID with your own.
-- Write a spreadsheet from a table by spreadsheet id
COPY <table_name> TO '11QdEasMWbETbFVxry-SsD8jVcdYIT1zBQszcF84MdE8' (FORMAT gsheet);
See the write options for appending data, selecting a range, and controlling overwrite behavior.
Available in Haybarn
This reference uses the published build for Haybarn 1.5.5.
Google Sheets is used from a native Haybarn session. Its published builds do not include WASM.