SheetReader
Read Excel workbooks as SQL tables. Choose a worksheet, handle header rows, and control column types.
Install
INSTALL sheetreader FROM community;
LOAD sheetreader;
Arguments & returns
sheetreader
Table functionSignature
Arguments
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
VARCHAR
|
Mode Positional | Description Path to the Excel workbook. |
Argument
coerce_to_string
|
Type
BOOLEAN
|
Mode Named |
Description
Default: false
Coerce all cells in column of type VARCHAR to string (i.e. VARCHAR).
|
Argument
force_types
|
Type
BOOLEAN
|
Mode Named |
Description
Default: false
Use types even if they are not compatible with types determined by first/second row. Cells, that are not of the column type, are set to NULL or coerced to string, if option is set.
|
Argument
has_header
|
Type
BOOLEAN
|
Mode Named |
Description
Default: false
Force to treat first row as header row.
|
Argument
threads
|
Type
INTEGER
|
Mode Named | Description Number of threads to use, while parsing |
Argument
sheet_index
|
Type
INTEGER
|
Mode Named | Description Default: 1 Index of the sheet to read. Starts at 1. |
Argument
types
|
Type
VARCHAR[]
|
Mode Named |
Description
List of types for all columns
|
Argument
skip_rows
|
Type
INTEGER
|
Mode Named | Description Default: 0 Number of rows to skip |
Argument
sheet_name
|
Type
VARCHAR
|
Mode Named |
Description
Default: ""
Name of the sheet to read. Only either sheet_index or sheet_name can be set.
|
Returns
Columns and types are determined from the selected worksheet. Use types to specify the column types.
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.
Query an Excel workbook
Download the sample workbook into your working directory. Its Sales worksheet contains product revenue that you can group with SQL.
SELECT product, sum(revenue) AS revenue
FROM sheetreader('sales.xlsx', sheet_name = 'Sales', has_header = true)
GROUP BY product
ORDER BY revenue DESC;
Output
| product | revenue |
|---|---|
| Coffee | 540 |
| Tea | 180 |
This build requires XLSX text cells to use shared strings. Inline string cells are not supported.
Choose how the workbook is read
CREATE TABLE my_data AS
FROM sheetreader(
'data.xlsx',
sheet_index=1, -- or sheet_name='Sales'
threads=8, -- parallel parsing
has_header=TRUE, -- specify header presence
skip_rows=0, -- skip empty rows at top
coerce_to_string=TRUE -- force columns to VARCHAR
);
Example from SheetReader’s documentation. Replace data.xlsx with your workbook.
Available in Haybarn
This reference uses the published build for Haybarn 1.5.5.
The example above is checked with native Haybarn. A WASM binary is published; this page does not yet offer a verified browser example.