Skip to main content

Query using SQL

Query one or more worksheets in a Google Sheets spreadsheet using SQLite syntax. Each worksheet is available as a SQL table using its worksheet name.

Only read-only SELECT queries are supported. Joins across worksheets are supported.

SQLite documentation: https://www.sqlite.org/docs.html

Common use cases​

  • Data Manipulation
  • Filter, join, or reshape spreadsheet data before using it in later Wrk Actions

Application​

  • Google Sheets

Inputs (what you have)​

NameDescriptionData TypeRequired?Example
Google Sheets Connected AccountThe Connected Account used to access the spreadsheetConnected AccountYes
Spreadsheet linkLink to the Google Sheets spreadsheet. Example: https://docs.google.com/spreadsheets/d/SPREADSHEET_IDURLYeshttps://docs.google.com/spreadsheets/d/SPREADSHEET_ID
SQL queryA read-only SQLite SELECT query to run against the spreadsheet worksheets. Worksheet names are used as table names. Defaults to Select * from Sheet1Text (Long)YesSelect * from Sheet1
Value formatHow cell values should be returned from Google Sheets. Formatted values include display formatting such as currency and dates. Unformatted values return calculated raw values. Formulas return the formula text in formula cellsPredefined Choice ListNoFormatted values
Sheet configsOptional per-worksheet overrides for header handling and start row. Provide one configuration object per worksheetList of objectsNoSee Sheet configs below

Sheet configs​

Use Sheet configs when a worksheet does not start on row 1, or when columns do not have headers. Add one configuration object per worksheet name.

NameDescriptionData TypeRequired?Example
Sheet nameWorksheet name to configure. Sheet name is case sensitiveTextYesSheet1
Columns do not have headers?If selected, columns are referred to as Col1, Col2, etc. for this worksheetTrue/FalseNofalse
Start rowFirst row to use when reading this worksheet. Use this to skip preamble rows above the header or data. Default 1IntegerNo1

Note: The value of inputs can either be a set value in the configuration of the Wrk Action within the Wrkflow, or a variable from the Data Library. These variables in the Data Library are the outputs of previous Wrk Actions in the Wrkflow.

Outputs (what you get)​

NameDescriptionData TypeRequired?Example
Output JSONJSON output of the query resultText (Long)No
Total number of rowsThe total number of rows returned by the SQL queryIntegerNo

Note: Custom Outputs can be configured to map columns from the query result into individual Data Library fields.

Outcomes​

NameDescription
SuccessThis status is selected if the query completed successfully and returned one or more rows.
No resultThis status is selected if the query completed successfully but returned no rows.

Requirements​

  • A Google Sheets Connected Account must be connected in Wrk.
  • The spreadsheet must be accessible to the Google account used by the Connected Account.

How it works​

  • Every worksheet in the spreadsheet is loaded and exposed as a SQL table named after the worksheet title.
  • Worksheet names that include spaces or special characters must be quoted in SQL. Example: SELECT * FROM "Order Details".
  • By default, the first row of each worksheet is treated as column headers.
  • Blank or duplicate header names are normalized for SQL use (blank headers become Col1, Col2, etc.; duplicates get a numeric suffix).
  • Value format defaults to formatted values (FORMATTED_VALUE). Choose unformatted values when you need raw calculated numbers instead of display strings such as $1.23. Choose formulas (FORMULA) when you need the formula text from formula cells.
  • Only read-only queries that start with SELECT are allowed. WITH (CTE), insert, update, delete, and other write statements are not supported.

Example queries​

Select all rows from a worksheet:

Select * from Sheet1

Filter rows:

Select Name, Country from Sheet1 where Country = 'Canada'

Join two worksheets:

Select Customers.Name, Orders.Total
from Customers
inner join Orders on Customers.CustomerId = Orders.CustomerId

Query a worksheet without headers (with Columns do not have headers? enabled in Sheet configs):

Select Col1, Col2 from Sheet1