Send Reports
This section covers SEND REPORT - Timbr's SQL-native reporting. A report runs one or more queries, renders each result as a CSV or a formatted Excel file, and delivers it by email (SMTP), to a folder (a local path or a mounted network drive such as SharePoint, SMB or NFS), or to cloud storage (Amazon S3 or Azure). Wrap the statement in a job to send it on a schedule.
You can work with reports in two ways:
- Ad-hoc - one
SEND REPORT ... ATTACH (...)statement holds the whole definition and sends it right away. - Stored -
CREATE REPORTsaves the definition once. Anyone with access to the ontology can then send it by name withSEND REPORT {report_name}, pass variable values and filters for each run, preview it, and review its run history.
The Reports page in the Timbr platform builds, runs and schedules stored reports without writing SQL. Every screen on that page maps to the statements on this page.
Currently supported delivery channels:
| Channel | USING | Delivers to | Prerequisite |
|---|---|---|---|
USING `{email_datasource}` | One or more recipients, as email attachments | An email datasource with your SMTP settings (see Create the email datasource) | |
| File | USING `file` | A directory on the Timbr server | The target directory must be reachable from the Timbr server / container (see File delivery) |
| Amazon S3 | USING `{s3_datasource}` | A bucket folder | An S3 datasource (see S3 and Azure delivery) |
| Azure | USING `{azure_datasource}` | A container folder | An Azure Blob Storage or Azure Datalake Storage datasource (see S3 and Azure delivery) |
How a report is built
Every ad-hoc report is one SEND REPORT statement with three parts:
- Destination (
USING) - an email, S3 or Azure datasource, or the built-infilechannel. - Options (
OPTIONS) - the recipients, subject and body for email, or the outputpathfor files, plus the Excel formatting options. - Attachments (
ATTACH) - one or more queries, each rendered to a CSV or Excel file at send time.
SEND REPORT {report_name}
USING `{channel}`
OPTIONS (
{option} = '{value}',
...
)
ATTACH (
FORMAT '{format}' FILENAME '{file_name}' QUERY {query_name} AS ({sql_query}),
...
)
Required information (the curly brackets {} should not be an input, they are used only as a variable substitution):
- {report_name} - A name for the report
- {channel} - The name of an email, S3 or Azure datasource, or
file - {option} / {value} - Report options (see Options reference)
- {format} -
CSV,XLSXorEXCEL(XLSXandEXCELare equivalent) - {file_name} - The attachment / output file name. Supports date patterns
- {query_name} - A name for the query
- {sql_query} - Any Timbr SQL query (concepts, views, cubes, or datasource tables)
The rest of the statement - attachments and Excel formatting - is identical for every channel, so the same ATTACH block can be emailed, written to a folder or uploaded to S3 or Azure.
A query runs in the current ontology by default. To run one query somewhere else, add ONTOLOGY and/or DATASOURCE after its name:
QUERY {query_name} [ONTOLOGY {ontology_name}] [DATASOURCE {datasource_name}] AS ({sql_query})
Stored reports
A stored report keeps the destination, options and attachments under a name, so the definition is written once and sent many times.
Create a report
CREATE [OR REPLACE] REPORT {report_name}
[DESCRIPTION '{description}']
[USING `{default_target}`]
[OPTIONS ( {option} = '{value}', ... )]
[ATTACH ( ... )]
The USING, OPTIONS and ATTACH clauses are the same as in an ad-hoc SEND REPORT. USING sets the report's default target, which any send can override.
Example - an Excel report with two sheets, emailed by default:
CREATE OR REPLACE REPORT daily_call_volume
DESCRIPTION 'Daily call volume and the longest calls for a date range.'
USING `email_ops`
OPTIONS (
recipients = '[email protected],[email protected]',
subject = 'Daily call volume - {{yyyy-MM-dd}}',
excel_table_format = 'TableStyleMedium2'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'call_volume_{{yyyy-MM-dd}}.xlsx' (
QUERY daily_volume AS (
SELECT CAST(started_at AS DATE) AS call_date, COUNT(*) AS total_calls
FROM timbr.`call`
WHERE started_at >= timbr_variable('from_date', 'date', CURRENT_DATE - INTERVAL '7' DAY)
GROUP BY CAST(started_at AS DATE)
ORDER BY call_date
) SHEET 'Daily volume' DESCRIPTION 'Daily call volume',
QUERY longest_calls AS (
SELECT call_id, started_at, call_duration
FROM timbr.`call`
WHERE started_at >= timbr_variable('from_date', 'date', CURRENT_DATE - INTERVAL '7' DAY)
ORDER BY call_duration DESC
LIMIT 20
) SHEET 'Longest calls'
)
)
Notes:
- Ontology. A report belongs to the ontology that was active when it was created, and its queries run there unless a query sets its own
ONTOLOGY. Report names are unique across all ontologies. - Validation.
CREATEruns every query once with no rows returned to check it and record its output columns. An invalid query fails the statement, and the error names the query. If a datasource is unreachable at creation time, addvalidate = 'false'to the options to skip the check. - Replace.
CREATEfails if the name already exists.CREATE OR REPLACEreplaces the definition, keeps the original owner and increases the report's version. - SQL is stored as written, including formatting and
timbr_variable(...)calls.
Change a report
Use ALTER REPORT to change part of a stored report without rewriting it:
ALTER REPORT {report_name} SET OPTIONS ( {option} = '{value}', ... ) -- add or update options
ALTER REPORT {report_name} UNSET OPTIONS ( {option}, ... ) -- remove options
ALTER REPORT {report_name} SET DESCRIPTION '{description}'
ALTER REPORT {report_name} SET TARGET `{target}`
ALTER REPORT {report_name} ADD ATTACHMENT FORMAT '{format}' FILENAME '{file_name}' ( QUERY ... , ... )
ALTER REPORT {report_name} UPDATE ATTACHMENT FORMAT '{format}' FILENAME '{file_name}' ( QUERY ... , ... )
ALTER REPORT {report_name} DROP ATTACHMENT '{file_name}'
ALTER REPORT {report_name} ADD QUERY {query_name} [TO ATTACHMENT '{file_name}'] [ONTOLOGY {o}] [DATASOURCE {d}]
AS ({sql_query}) [SHEET '{sheet}'] [DESCRIPTION '{title}'] [CONDITIONAL_FORMAT '[...]']
ALTER REPORT {report_name} UPDATE QUERY {query_name} [ONTOLOGY {o}] [DATASOURCE {d}]
[AS ({sql_query})] [SHEET '{sheet}'] [DESCRIPTION '{title}'] [CONDITIONAL_FORMAT '[...]']
ALTER REPORT {report_name} DROP QUERY {query_name}
- An attachment is identified by its
FILENAMEtemplate. To rename a file, drop the attachment and add it again. UPDATE ATTACHMENTreplaces the format and all the attachment's queries.UPDATE QUERYchanges only the parts you give, and the query keeps its place.ADD QUERYwithoutTO ATTACHMENTcreates a new attachment for the query, named{query_name}.csvor.xlsxaccording to thedefault_formatoption (CSV by default).- Dropping the last query of an attachment drops the attachment.
ADDfails if the item already exists;UPDATEandDROPfail if it doesn't.- Every
CREATEandALTERincreases the report's version.
After the ontology changes (for example a renamed property), refresh the stored output columns and variables:
REFRESH REPORT {report_name}
Send a stored report
SEND REPORT {report_name}
[USING `{target}`]
[OPTIONS ( {option} = '{value}', ... )]
[WHERE {condition}]
[FILTER QUERY {query_name} ( WHERE {condition} )] ...
Without ATTACH, Timbr sends the stored report. A USING or OPTIONS given in the statement overrides the stored value for this run only, key by key.
Example - send the report as stored:
SEND REPORT daily_call_volume
Example - a test send to yourself, without changing the report:
SEND REPORT daily_call_volume OPTIONS ( recipients = '[email protected]' )
Example - write this run to a folder instead of emailing it:
SEND REPORT daily_call_volume USING `file` OPTIONS ( path = '/mnt/reports/' )
A SEND REPORT that includes ATTACH is always ad-hoc, even if a stored report has the same name. The stored report isn't read or changed.
Drop a report
DROP REPORT [IF EXISTS] {report_name}
Jobs that send the report aren't dropped with it. Drop them with DROP JOB.
Variables
Variables let one report serve many runs. Values such as a date range or a list of regions are chosen when the report is sent.
Declare a variable
There is no separate declaration. Call timbr_variable inside a query, or write {{variable.name}} in a text field (subject, body, path, FILENAME, sheet DESCRIPTION):
timbr_variable('{name}' [, '{type}' [, {default}]])
WHERE call_date >= timbr_variable('from_date', 'date', CURRENT_DATE - INTERVAL '7' DAY)
AND region IN (timbr_variable('regions'))
AND amount >= timbr_variable('min_amount', 'decimal', '0')
| Part | Description |
|---|---|
name | The variable name. The same name in several queries is the same variable |
type | string (default), varchar, int, integer, bigint, decimal, double, date, timestamp or boolean |
default | Optional. A quoted value or list ('0', 'TX,CA'), a SQL expression (CURRENT_DATE - INTERVAL '1' DAY), or a subquery (for a list variable, each row is one value). Evaluated once per run, in the report's ontology |
Timbr works out the rest from how the variable is used:
- Single or list. A variable inside an
IN (...)orNOT IN (...)list accepts several values. Anywhere else it accepts one value. - Required or optional. A variable without a default is required. A run without a value fails before any query runs, with
Missing value for variable(s) [name]. - Consistency. Every use of the same name must agree on type, default, and single or list, or
CREATEfails.
Built-in variables are always available without a default: run_ts, run_date, report_name, run_id, timbr_username, and in jobs, job_name and job_id.
The variables of each report are listed in SYS_REPORT_VARIABLES.
Pass values
Give values in OPTIONS with a variable. prefix. Option names that contain a dot must be wrapped in backticks:
SEND REPORT daily_call_volume OPTIONS (
`variable.from_date` = '2026-10-01', -- date: yyyy-MM-dd, timestamp: yyyy-MM-dd HH:mm:ss
`variable.regions` = 'North,South', -- list: comma separated
`variable.customers` = '"Acme, Inc.",Globex' -- quote a value that contains a comma; "" is a quote
)
- A variable you don't pass uses its default, evaluated at run time.
- Values are checked against the type before any query runs (
Invalid value 'abc' for variable 'min_amount' (type int)), and are inserted as SQL literals, never as SQL text. - An unknown
variable.name is an error. - In text fields, a list value is written as the values separated by a comma and a space.
Filter a run
A send can narrow the rows of a stored report without editing it:
SEND REPORT {report_name}
[WHERE {condition}] -- applies to every query of the report
[FILTER QUERY {query_name} ( WHERE {condition} )] -- applies to one query; once per query
Example:
SEND REPORT daily_call_volume
OPTIONS ( `variable.from_date` = '2026-10-01' )
FILTER QUERY daily_volume ( WHERE total_calls >= 10 )
Rules:
- Conditions use the query's output column names, unqualified. The columns of each query are listed in
SYS_REPORT_QUERY_COLUMNS. - Allowed: columns, literals,
timbr_variable(...),=,<>,!=,<,>,<=,>=,IN,NOT IN,LIKE,BETWEEN,IS [NOT] NULL,AND,OR,NOTandCAST. Subqueries and other functions aren't allowed. - A
WHEREcolumn must exist in every query of the report. If it doesn't, the error names the query; useFILTER QUERYfor that query instead. WHEREandFILTER QUERYon the same query are combined withAND.- A query that ends with
LIMITcan't be filtered. - The filtered query runs as
SELECT * FROM ({query}) WHERE {condition}. A trailingORDER BYon output columns is kept.
Preview a report
PREVIEW REPORT shows what a send would do. It never delivers anything and doesn't write run history.
-- what would be delivered: one row, the attached queries don't run
PREVIEW REPORT {report_name} [USING `{target}`] [OPTIONS (...)] [ATTACH (...)] [WHERE ...] [FILTER QUERY ...]
-- the rows one query returns, with variables and filters applied
PREVIEW REPORT {report_name} QUERY {query_name} [OPTIONS (...)] [ATTACH (...)] [WHERE ...] [FILTER QUERY ...] [LIMIT n]
The delivery preview returns one row:
| Column | File, S3, Azure | |
|---|---|---|
target | Datasource name | file or the datasource name |
target_type | email | file, s3 or azure |
from | Sender address | NULL |
recipients | JSON array | NULL |
subject | Resolved subject | NULL |
body_type | text or html | NULL |
body | Resolved body | NULL |
files | JSON array of attachment file names | JSON array of full paths or URIs |
variables | JSON object: each variable's value and where it came from (options, builtin or default) | Same |
The query preview returns 5 rows by default. Set LIMIT for more, up to 1,000 rows (the server default maximum).
Add ATTACH (...) to preview a query or a definition before you save it.
Run history and saved results
Every send of a stored or ad-hoc report is recorded:
SHOW REPORTS HISTORY -- same as SELECT * FROM timbr.sys_report_history, newest first
SYS_REPORT_HISTORYhas one row per run: who ran it, whether a job started it, the target and recipients, the variable values and filters, timing, status and delivered locations.SYS_REPORT_HISTORY_RESULTShas one row per query in the run, with the SQL that ran after variables and filters were applied, the row count and the size.
A run's status is RUNNING, then SUCCESS, ERROR, or SKIPPED (see skip_if_empty in the options reference). When a run fails, error_type tells you at which stage:
error_type | Meaning |
|---|---|
validation | A variable, option, filter or target was rejected before any query ran |
query | A query failed |
send | Delivery failed (SMTP, file, S3 or Azure) |
system | An internal error |
See Report tables for all the columns.
Saved results
Set save_results = 'true' on a report to keep the result set of every query in each run. You can read a saved result back later:
SHOW REPORT RESULTS '{run_id}' [QUERY {query_name}]
- Saving is off unless the report or your administrator turns it on.
- Only administrators and the report's owner can read saved results.
- Very large result sets aren't saved. In that case
truncatedis1inSYS_REPORT_HISTORY_RESULTS.
List, inspect and copy reports
SHOW REPORTS -- same as SELECT * FROM timbr.sys_reports
SHOW CREATE REPORT {report_name} -- the statement that recreates the report
EXPORT REPORT {report_name} [OVERWRITE] TO {new_name} -- copy a report under a new name
- You see the reports of the ontologies you have access to.
EXPORT REPORTfails if{new_name}already exists, unless you addOVERWRITE.- Changes to a report definition are logged in
SYS_ONTOLOGY_HISTORYwithresource_type = 'REPORT'.
Create the email datasource (SMTP)
Sending a report by email requires an email datasource in Timbr. Create it once with your SMTP settings; every email report reuses it by name in the USING clause.
CREATE OR REPLACE DATASOURCE `{email_datasource}`
OPTIONS (
JSON '{
"config": {
"smtp_host": "{smtp_host}",
"smtp_port": {smtp_port},
"from": "{from_address}",
"username": "{smtp_user}",
"password": "%PASSWORD%",
"tls": {true|false},
"ssl": {true|false}
}
}',
TYPE 'email',
PASSWORD '{smtp_password}'
)
| Setting | Required | Default | Description |
|---|---|---|---|
smtp_host | Yes | - | SMTP server hostname, e.g. smtp.office365.com, smtp.gmail.com, email-smtp.us-east-1.amazonaws.com |
smtp_port | No | 587 | 587 for TLS (STARTTLS), 465 for SSL |
from | No | username | Sender address shown to recipients. If omitted, the username is used |
username | No | - | SMTP user for authentication |
password | No | - | Put the literal placeholder "%PASSWORD%" in the JSON and the real value in the PASSWORD clause, so the credential is not stored in plain text |
tls | No | true | Enable STARTTLS |
ssl | No | false | Enable implicit SSL (typically with port 465) |
Authentication is used only when both username and password are provided. Some internal SMTP relays don't require authentication - in that case omit both.
Example - Office 365 (TLS on port 587):
CREATE OR REPLACE DATASOURCE `email_ops`
OPTIONS (
JSON '{
"config": {
"smtp_host": "smtp.office365.com",
"smtp_port": 587,
"from": "[email protected]",
"username": "[email protected]",
"password": "%PASSWORD%",
"tls": true,
"ssl": false
}
}',
TYPE 'email',
PASSWORD 'my_secure_password'
)
Example - Amazon SES (SSL on port 465), with a sender address that differs from the SMTP user:
CREATE OR REPLACE DATASOURCE `email_ops`
OPTIONS (
JSON '{
"config": {
"smtp_host": "email-smtp.us-east-1.amazonaws.com",
"smtp_port": 465,
"from": "[email protected]",
"username": "<SES_SMTP_USER>",
"password": "%PASSWORD%",
"tls": true,
"ssl": true
}
}',
TYPE 'email',
PASSWORD '<SES_SMTP_PASSWORD>'
)
See Datasource for managing datasources in general (show, describe, remove).
Send a report by email
Recipients are set with the recipients option. A report can be sent to a single user or to multiple users - separate addresses with commas. Distribution lists / group mailboxes work as well.
SEND REPORT {report_name}
USING `{email_datasource}`
OPTIONS (
recipients = '{email_1},{email_2},...',
subject = '{subject}',
body = '{body}'
)
ATTACH (
FORMAT '{format}' FILENAME '{file_name}' QUERY {query_name} AS ({sql_query})
)
Example - one recipient, one CSV attachment:
SEND REPORT daily_orders
USING `email_ops`
OPTIONS (
recipients = '[email protected]',
subject = 'Daily Orders',
body = 'Please find today''s orders attached.'
)
ATTACH (
FORMAT 'CSV' FILENAME 'orders.csv' QUERY orders AS (SELECT * FROM timbr.sales_order WHERE order_date = CURRENT_DATE)
)
Example - several recipients, several attachments in one email:
SEND REPORT daily_report
USING `email_ops`
OPTIONS (
recipients = '[email protected],[email protected],[email protected]',
subject = 'Daily Report',
body = 'Please find the persons report attached.
2 files attached.'
)
ATTACH (
FORMAT 'CSV' FILENAME 'persons.csv' QUERY persons AS (SELECT * FROM timbr.person),
FORMAT 'CSV' FILENAME 'persons_raw.csv' QUERY raw AS (SELECT * FROM test.persons)
)
Escape a single quote inside a value by doubling it ('today''s report'). Line breaks inside the body value are kept as-is.
Plain-text and HTML bodies
By default the email body is plain text. Set body_type = 'html' to send an HTML body - useful for headings, emphasis, links and light branding. Then put complete HTML in body.
body_type | Behavior |
|---|---|
text (default) | Body sent as plain text, exactly as written |
html | Body sent as HTML; you provide the markup |
SEND REPORT exec_summary
USING `email_ops`
OPTIONS (
recipients = '[email protected]',
subject = 'Executive Summary - {{yyyy-MM-dd}}',
body_type = 'html',
body = '<h2>Executive Summary</h2>
<p>Revenue is up <b>12%</b> week over week. The full breakdown is attached.</p>'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'exec_summary.xlsx'
QUERY revenue AS (SELECT region, SUM(revenue) AS total_revenue FROM timbr.sales_order GROUP BY region)
)
File delivery (local or network drive)
Use the built-in file channel and set path to a directory as seen from the Timbr server. No datasource is needed. The directory is created if it doesn't exist.
SEND REPORT {report_name}
USING `file`
OPTIONS (
path = '{output_directory}'
)
ATTACH (
FORMAT '{format}' FILENAME '{file_name}' QUERY {query_name} AS ({sql_query})
)
Example - a timestamped CSV snapshot:
SEND REPORT inventory_snapshot
USING `file`
OPTIONS (
path = '/mnt/reports/daily/'
)
ATTACH (
FORMAT 'CSV' FILENAME 'inventory_{{yyyy-MM-dd_HHmmss}}.csv'
QUERY inv AS (SELECT warehouse, product_sku, stock_qty FROM timbr.inventory_item ORDER BY stock_qty ASC)
)
To deliver reports to SharePoint, a Windows/SMB file share, or an NFS share, the share must be mounted into the filesystem of the Timbr server. In a container deployment (Docker / Kubernetes) this is done by your IT / DevOps team: mount the share as a volume into the Timbr server container (for example at /mnt/reports), and make sure the container user has write permission on it. Then use the mount point inside the container as the path.
For SharePoint, sync or map the document library to an SMB/WebDAV location that can be mounted on the host, and mount that location into the container.
| Behavior | Detail |
|---|---|
path | Required. Output directory - local or network-mounted |
| One attachment per statement | The file channel writes one file per SEND REPORT. For several datasets in one file, use a multi-sheet Excel workbook |
| Unique file names | Use a date pattern in the FILENAME (e.g. {{yyyy-MM-dd_HHmmss}}) so each run produces a new file instead of overwriting the previous one |
S3 and Azure delivery
To upload report files to cloud storage, use an S3, Azure Blob Storage or Azure Datalake Storage datasource as the target and set path to the folder URI. Create the datasource once (see Datasource); every report reuses it by name.
SEND REPORT {report_name}
USING `{storage_datasource}`
OPTIONS (
path = '{folder_uri}',
overwrite = '{true|false}'
)
| Target | path example |
|---|---|
| Amazon S3 | s3a://my-bucket/reports/daily/ |
| Azure | abfss://[email protected]/daily/ |
| Option | Default | Description |
|---|---|---|
path | - | Required. The folder URI. Supports date patterns and {{variable.name}}. A variable value can't add a / to the path |
overwrite | false | With false, the send fails if a file with the same name already exists |
sse | - | S3 only. Server-side encryption: AES256 or aws:kms |
sse_kms_key_id | - | S3 only. The KMS key ID when sse = 'aws:kms' |
Example - a stored report uploaded to S3 every run under a dated folder:
CREATE OR REPLACE REPORT inventory_to_s3
USING `s3_reports`
OPTIONS (
path = 's3a://acme-reports/inventory/{{yyyy-MM-dd}}/',
sse = 'AES256'
)
ATTACH (
FORMAT 'CSV' FILENAME 'inventory.csv'
QUERY inv AS (SELECT warehouse, product_sku, stock_qty FROM timbr.inventory_item)
)
Attachment formats: CSV and Excel
Each attachment declares its own FORMAT. Both channels support both formats.
| Format | Keyword | Best for |
|---|---|---|
| CSV | FORMAT 'CSV' | Raw data, unlimited rows, loading into other tools |
| Excel | FORMAT 'XLSX' or FORMAT 'EXCEL' | Presentation-ready workbooks: styled tables, typed numbers and dates, filters, multiple sheets, conditional formatting |
CSV
CSV attachments contain a header row with the query's column names followed by all result rows. CSV has no row limit, so use it whenever the recipient needs the complete dataset or will load it into another system. Non-Latin text is fully supported.
Excel-only features (SHEET, DESCRIPTION, CONDITIONAL_FORMAT, table styles, colors) do not apply to CSV. Using CONDITIONAL_FORMAT on a CSV attachment is an error.
Excel
Timbr writes numbers, decimals, dates and timestamps as real Excel values with appropriate number formats - so they sort, filter and calculate correctly in the recipient's spreadsheet with no clean-up. Column headers come from the query's column names or aliases.
SEND REPORT weekly_sales
USING `email_ops`
OPTIONS (
recipients = '[email protected]',
subject = 'Weekly Sales Summary',
body = 'Attached is this week''s sales summary.'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'weekly_sales.xlsx'
QUERY sales AS (
SELECT region, SUM(revenue) AS total_revenue, COUNT(order_id) AS orders
FROM timbr.sales_order
GROUP BY region ORDER BY total_revenue DESC
)
)
The sections below describe the Excel formatting options. Excel options are set in OPTIONS and apply to every Excel attachment and every sheet in the report, on either channel.
Excel: table styles
Set excel_table_format to any built-in Excel table style name. Timbr turns each sheet into a native Excel table with a styled header, banded rows and - by default - a filter drop-down on every column.
SEND REPORT monthly_revenue
USING `email_ops`
OPTIONS (
recipients = '[email protected]',
subject = 'Monthly Revenue by Category',
body = 'This month''s revenue breakdown is attached.',
excel_table_format = 'TableStyleMedium9'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'monthly_revenue.xlsx'
QUERY revenue AS (SELECT category, SUM(net_revenue) AS net_revenue FROM timbr.sales_order GROUP BY category ORDER BY net_revenue DESC)
)
Style names follow Excel's own Table Styles gallery - open the gallery in Excel to preview them:
| Family | Names | Look |
|---|---|---|
| Light | TableStyleLight1 - TableStyleLight21 | Subtle banding, understated header. Good for dense data |
| Medium | TableStyleMedium1 - TableStyleMedium28 | Colored header, clear banding. The most common choice |
| Dark | TableStyleDark1 - TableStyleDark11 | Strong colored header, high contrast |
If you omit excel_table_format, smaller reports get a clean default light style (TableStyleLight16) while larger reports get a simple bold header. When appearance matters, always set excel_table_format so every run looks the same regardless of row count.
Excel: header colors and filters
Header background color (without a table style)
For a plain sheet with just a colored header - rather than a banded table - leave excel_table_format unset and set excel_header_background_color:
| Value | Result |
|---|---|
NONE (default) | Bold header, no fill |
BLUE | Blue header, white text |
GREEN | Green header, white text |
ORANGE | Orange header, white text |
TEAL | Teal header, white text |
RED | Red header, white text |
GREY | Grey header, black text |
SEND REPORT daily_people
USING `file`
OPTIONS (
path = '/mnt/reports/',
excel_header_background_color = 'BLUE'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'people_{{yyyy-MM-dd_HHmmss}}.xlsx' QUERY people AS (SELECT * FROM timbr.person)
)
If excel_table_format is set, the table style controls the header and excel_header_background_color is ignored.
Header text color
table_header_color controls the header text color. The default, AUTO, picks black or white so the header stays legible against its background.
| Value | Result |
|---|---|
AUTO (default) | Chosen automatically for legibility |
BLACK | Always black header text |
WHITE | Always white header text |
Column filters
Filter drop-downs are enabled by default so recipients can sort and filter immediately. Turn them off with excel_filter_table = 'false'.
Excel: sheet names and titles
Name the worksheet tab with SHEET and add a title row above the table with DESCRIPTION. To use either, wrap the query in parentheses:
ATTACH (
FORMAT 'XLSX' FILENAME 'revenue.xlsx' (
QUERY revenue AS (SELECT category, SUM(net_revenue) AS net_revenue FROM timbr.sales_order GROUP BY category)
SHEET 'Revenue' DESCRIPTION 'Net revenue by category - {{yyyy-MM}}'
)
)
Multiple sheets in one workbook
List several queries inside the parentheses, separated by commas. Each query becomes its own tab with its own name, title and conditional formatting - delivering a whole reporting pack as a single file.
SEND REPORT quarterly_pack
USING `email_ops`
OPTIONS (
recipients = '[email protected],[email protected]',
subject = 'Quarterly Pack',
body = 'Revenue and pipeline are attached as one workbook.',
excel_table_format = 'TableStyleMedium9'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'quarterly_pack.xlsx' (
QUERY revenue AS (SELECT category, SUM(net_revenue) AS net_revenue
FROM timbr.sales_order GROUP BY category ORDER BY net_revenue DESC)
SHEET 'Revenue' DESCRIPTION 'Net revenue by category',
QUERY pipeline AS (SELECT stage, COUNT(*) AS opportunities, SUM(amount) AS value
FROM timbr.opportunity GROUP BY stage)
SHEET 'Pipeline' DESCRIPTION 'Open opportunities by stage'
)
)
You can also mix forms in one email - for example one multi-sheet workbook plus a separate CSV:
ATTACH (
FORMAT 'XLSX' FILENAME 'summary.xlsx' (
QUERY people AS (SELECT * FROM timbr.person) SHEET 'People' DESCRIPTION 'People from the ontology',
QUERY raw AS (SELECT * FROM test.persons) SHEET 'Raw' DESCRIPTION 'Raw source rows'
),
FORMAT 'CSV' FILENAME 'people_full.csv' QUERY people_full AS (SELECT * FROM timbr.person)
)
The report-level Excel options (excel_table_format, header color, filters, righttoleft, table_limit) apply consistently to every sheet in the workbook.
Excel: conditional formatting
Color cells or whole rows by rule - thresholds, value matches, comparisons to another column, and set membership. Conditional formatting is defined per query (rules refer to that query's columns), so CONDITIONAL_FORMAT goes inside the parenthesized attach form, next to SHEET and DESCRIPTION. It takes a JSON array of rules.
ATTACH (
FORMAT 'XLSX' FILENAME '{file_name}' (
QUERY {query_name} AS ({sql_query})
SHEET '{sheet_name}'
CONDITIONAL_FORMAT '[ {rule}, {rule}, ... ]'
)
)
- Excel only -
CONDITIONAL_FORMATon aCSVattachment is an error. - Rules are evaluated in array order. When two matching rules set the same property of a cell (for example, both set the fill), the earlier rule wins.
- By default a rule colors only the tested cell. Add
"scope": "row"to color every cell of the matching row (see Cell or row). Cells that match no rule keep the sheet's normal styling.
Rule fields
| Field | Required | Description |
|---|---|---|
column | Yes | The output column name (alias) from the query's SELECT list. Not case-sensitive |
op | Yes | The operator (see below) |
value | Exactly one of these three | Compare to a constant (number, string or boolean) |
other_column | Compare to another column in the same row (comparison operators only) | |
values | A non-empty list, for in / not_in | |
background_color | At least one of these two | Named color or #RRGGBB |
font_color | Named color or #RRGGBB. Derived automatically from a named background_color if omitted | |
scope | No | cell (default): color only the tested cell. row: color every cell of the matching row |
Operators
| Kind | Operators |
|---|---|
| Comparison | > < >= <= = (or ==) != (or <>) |
| String | contains, starts_with, ends_with |
| Set | in, not_in - require a non-empty values list |
Colors
background_color and font_color accept a named color or any #RRGGBB hex value. A named fill comes with a matching text color, so "background_color": "RED" alone gives the full preset. A hex fill has no automatic text color.
| Light (soft fill, dark text) | Fill | Auto font | Dark (strong fill, white text) | Fill | Auto font | |
|---|---|---|---|---|---|---|
RED | #FFC7CE | #9C0006 | DARK_RED | #C00000 | #FFFFFF | |
GREEN | #C6EFCE | #006100 | DARK_GREEN | #375623 | #FFFFFF | |
YELLOW | #FFEB9C | #9C6500 | DARK_YELLOW | #BF8F00 | #FFFFFF | |
BLUE | #DDEBF7 | #2F5496 | DARK_BLUE | #2F5496 | #FFFFFF | |
GREY | #E7E6E6 | #3F3F3F | DARK_GREY | #767171 | #FFFFFF |
Color names are not case-sensitive. Setting font_color overrides the automatic text color.
Cell or row
scope sets how much of the sheet a matching rule colors:
scope | Result for {"column": "net", "op": "<", "value": 0, "background_color": "RED"} |
|---|---|
cell or omitted | Only the net cell is red, in rows where net < 0 |
row | Every cell is red, in rows where net < 0 |
A cell rule and a row rule can match the same cell. If both set the same property, the earlier rule in the array wins, so list row rules after cell rules when the cell highlight should stay visible:
[
{ "column": "net", "op": "<", "value": -1000, "background_color": "DARK_RED" },
{ "column": "net", "op": "<", "value": 0, "background_color": "RED", "scope": "row" }
]
Rule examples
Threshold split:
[
{ "column": "score", "op": ">", "value": 50, "background_color": "GREEN" },
{ "column": "score", "op": "<=", "value": 50, "background_color": "RED" }
]
Highlight a status value (font color is derived automatically as white):
[
{ "column": "status", "op": "=", "value": "OVERDUE", "background_color": "DARK_RED" }
]
Compare to another column:
[
{ "column": "net", "op": ">", "other_column": "gross", "background_color": "GREEN" }
]
Set membership, with a custom hex fill and font:
[
{ "column": "status", "op": "in", "values": ["OVERDUE", "DISPUTED", "VOID"],
"background_color": "#FFEB9C", "font_color": "#9C0006" }
]
Text match:
[
{ "column": "customer_name", "op": "starts_with", "value": "ACME", "background_color": "BLUE" }
]
Full example - per-sheet rules
SEND REPORT people_review
USING `email_ops`
OPTIONS (
recipients = '[email protected]',
subject = 'People review',
body = 'Two sheets, each with its own highlighting.'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'people_review.xlsx' (
QUERY people AS (SELECT * FROM timbr.person) SHEET 'People'
CONDITIONAL_FORMAT '[
{ "column": "age", "op": "<", "value": 18, "background_color": "RED" }
]',
QUERY raw AS (SELECT * FROM test.persons) SHEET 'Raw'
CONDITIONAL_FORMAT '[
{ "column": "age", "op": ">=", "value": 65, "background_color": "DARK_BLUE" },
{ "column": "age", "op": "in", "values": [18, 21, 30], "background_color": "YELLOW" }
]'
)
)
Interaction with table styles
Conditional formatting is layered on top of the sheet's table styling:
excel_table_format set? | CONDITIONAL_FORMAT set? | Result |
|---|---|---|
| No | No | Default table style (TableStyleLight16) |
| No | Yes | No table style - plain bold header (plus optional excel_header_background_color), filters kept, rules on top. The default banding is skipped so it doesn't compete with the rule colors |
| Yes | No | Your table style |
| Yes | Yes | Your table style with the rules on top |
Validation
Rules are validated when the report is sent. Any problem fails the statement immediately with a clear error message, rather than producing a silently uncolored workbook:
- Unknown or missing
column/other_column- the error lists the available columns - Not exactly one of
value/other_column/values - Empty
valuesforin/not_in - Unknown operator - the error lists the valid operators
- Invalid color name or hex value
- Neither
background_colornorfont_colorprovided - A
scopeother thancellorrow CONDITIONAL_FORMATon a non-Excel attachment
Excel: column width and wrap
By default, every column of an Excel sheet is sized to fit its content. These options change that. They are report-level options, so they apply the same way to every sheet of every Excel attachment in the report. CSV attachments ignore them.
| Option | Default | Description |
|---|---|---|
excel_autosize | true | true: fit each column to its content. false: columns keep Excel's default width (about 8.4 characters), unless a fixed width applies |
excel_max_width | Not set | The maximum width of an auto-fitted column, in characters (1-255). When not set, small single-sheet reports have no maximum, and larger or multi-sheet reports stop at 80 |
excel_column_width | Not set | The same fixed width for every column, in characters (1-255). Columns aren't auto-fitted |
excel_column_widths | Not set | Fixed widths for specific columns: 'column:width,column:width', for example 'net:12,description:60'. Column names aren't case-sensitive, and a name that isn't in a sheet is ignored |
excel_wrap_text | false | true: long text wraps onto several lines inside the cell, in the header and the data. Excel grows the row height when the file is opened |
Widths are in characters of the default font, Excel's own column-width unit. Each column's width comes from the first rule that applies:
- The column is listed in
excel_column_widths: that width. excel_column_widthis set: that width.excel_autosize = 'false': Excel's default width.- Otherwise the column is fitted to its content, up to
excel_max_widthif it is set.
-- Fit columns to their content, but never wider than 40 characters, and wrap long text
OPTIONS ( excel_max_width = '40', excel_wrap_text = 'true' )
-- The same width for every column, except a wide description column
OPTIONS ( excel_column_width = '15', excel_column_widths = 'description:60' )
-- No fitting at all; set only the id column
OPTIONS ( excel_autosize = 'false', excel_column_widths = 'id:8' )
Use excel_wrap_text together with excel_max_width or a fixed width. On its own, auto-fit makes each column wide enough that nothing needs to wrap.
An invalid width, such as text or a number outside 1-255, fails the send with an error that names the option.
Excel: row limits
Excel attachments include up to 50,000 rows per sheet by default. Adjust with table_limit, up to Excel's maximum of 1,048,576 rows per sheet.
OPTIONS (
recipients = '[email protected]',
subject = 'Full Transaction Export',
table_limit = '200000'
)
| Behavior | Detail |
|---|---|
| Default | 50,000 rows per sheet |
| If exceeded | The first N rows (in query order) are included; the rest are omitted |
| Maximum | 1,048,576 rows per sheet |
| Unlimited | Use FORMAT 'CSV' - CSV has no row limit |
Add an ORDER BY when a result may exceed the limit, so "the first N rows" is meaningful and repeatable. For a guaranteed complete dataset, use CSV.
Right-to-left reports
For recipients who read a right-to-left language, set righttoleft = 'true'. This one option adjusts:
- Excel - the worksheet is laid out right-to-left (columns run from right to left, text is right-aligned).
- Email body - a plain-text body is rendered right-to-left.
righttoleft only controls layout direction - the data itself renders correctly in any language regardless of this setting. With an HTML body (body_type = 'html'), set the direction in your own HTML instead (e.g. <div dir="rtl">).
SEND REPORT weekly_report_rtl
USING `email_ops`
OPTIONS (
recipients = '[email protected]',
subject = 'Weekly Report',
body = 'The weekly report is attached.',
excel_table_format = 'TableStyleMedium9',
righttoleft = 'true'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'weekly_report.xlsx' (
QUERY people AS (SELECT name, age FROM timbr.person)
SHEET 'Report' DESCRIPTION 'People'
)
)
Date patterns in file names, subjects and bodies
Add a date/time stamp with a {{format}} placeholder, where format is a Java DateTimeFormatter pattern. Each placeholder is replaced with the current date and time when the report is sent, on both the email and file channels, in these fields:
| Field | Example | Result |
|---|---|---|
Attachment FILENAME | 'output_{{yyyyMMdd}}.csv' | output_20260518.csv |
Attachment FILENAME | 'report_{{yyyy-MM-dd_HHmmss}}.csv' | report_2026-05-18_143022.csv |
Attachment FILENAME | 'data_{{yyyyMMdd_HHmm}}.csv' | data_20260518_1430.csv |
Email subject | 'Revenue - {{yyyy-MM-dd}}' | Revenue - 2026-05-18 |
Email body | 'Attached: revenue as of {{dd/MM/yyyy HH:mm}}.' | Attached: revenue as of 18/05/2026 14:30. |
Sheet DESCRIPTION | 'Net revenue - {{yyyy-MM}}' | Net revenue - 2026-05 |
Everything between {{ and }} is the pattern; text outside the braces is kept as-is, and a field can contain several placeholders (e.g. 'sales_{{yyyy}}_{{MM}}.xlsx').
Common pattern letters:
| Letter | Meaning | Example |
|---|---|---|
yyyy / yy | Year | 2026 / 26 |
MM | Month (01-12) | 05 |
dd | Day of month (01-31) | 18 |
HH | Hour (00-23) | 14 |
mm | Minute | 30 |
ss | Second | 22 |
Notes:
- Server time. The date and time are the Timbr server's local date and time (the server / container time zone), taken at the moment the report is sent. For a scheduled job, that is the time the job runs.
- No time-zone letters. The value has no time-zone information, so zone/offset letters (
z,Z,X,x,O,V) are not supported. - Invalid patterns fail the statement. An unrecognized pattern letter causes the
SEND REPORTto fail with an error rather than sending a report with a broken name. - File-name characters. Don't use characters that are invalid in file names (such as
/,\or:) in aFILENAMEpattern - use-or_as separators instead.
For scheduled reports written to a folder, include a timestamp in the FILENAME (e.g. {{yyyy-MM-dd_HHmmss}}) so each run creates a new file instead of overwriting the previous one.
Variable values in text fields
{{variable.name}} writes a variable's value into the same fields, plus path. For example, subject = 'Calls from {{variable.from_date}}' becomes Calls from 2026-10-01.
Schedule a report with a job
Wrap any SEND REPORT in CREATE OR REPLACE JOB to send it automatically - by email or to a folder, on any cadence. See Jobs for the full jobs reference (retries, RUN JOB, bulk jobs).
CREATE OR REPLACE JOB {job_name}
REFRESH '{refresh_value}'
AS SEND REPORT {report_name}
USING `{channel}`
OPTIONS ( ... )
ATTACH ( ... )
{refresh_value} can be none (runs only when invoked with RUN JOB), daily, weekly, monthly, yearly, or a cron expression.
For a stored report, the job sends the report by name. Variable values, filters and overrides are part of the job:
CREATE OR REPLACE JOB daily_call_volume_weekly
REFRESH '0 6 * * 1'
AS SEND REPORT daily_call_volume
OPTIONS ( `variable.from_date` = '2026-10-01' )
FILTER QUERY daily_volume ( WHERE total_calls >= 10 )
One job can send several reports:
CREATE OR REPLACE JOB monday_reports
REFRESH '0 7 * * 1'
AS BEGIN
SEND REPORT daily_call_volume;
SEND REPORT customers_by_city OPTIONS ( `variable.cities` = 'Central,Gateway' );
END
A variable left out of the job uses its default, evaluated each time the job runs. That makes defaults such as CURRENT_DATE - INTERVAL '7' DAY a good fit for scheduled reports. Runs started by a job appear in SYS_REPORT_HISTORY with trigger_type = 'job' and the job's job_id.
The ad-hoc examples below include the whole definition in the job:
Example - a formatted two-sheet Excel pack emailed every Monday at 07:00:
CREATE OR REPLACE JOB weekly_finance_pack
REFRESH '0 7 * * 1'
RETRY '3'
RETRY INTERVAL '300'
AS SEND REPORT finance_weekly
USING `email_ops`
OPTIONS (
recipients = '[email protected],[email protected]',
subject = 'Weekly Finance Pack - {{yyyy-MM-dd}}',
body_type = 'html',
body = '<p>Good morning. This week''s <b>revenue</b> and <b>pipeline</b> pack is attached.</p>',
excel_table_format = 'TableStyleMedium9',
table_limit = '100000'
)
ATTACH (
FORMAT 'XLSX' FILENAME 'finance_pack_{{yyyyMMdd}}.xlsx' (
QUERY revenue AS (SELECT category, SUM(net_revenue) AS net_revenue, SUM(gross_revenue) AS gross_revenue
FROM timbr.sales_order WHERE order_date >= CURRENT_DATE - 7
GROUP BY category ORDER BY net_revenue DESC)
SHEET 'Revenue' DESCRIPTION 'Net & gross revenue - week ending {{yyyy-MM-dd}}'
CONDITIONAL_FORMAT '[
{ "column": "net_revenue", "op": "<", "value": 0, "background_color": "RED" }
]',
QUERY pipeline AS (SELECT stage, COUNT(*) AS opportunities, SUM(amount) AS value
FROM timbr.opportunity WHERE status = 'open'
GROUP BY stage ORDER BY value DESC)
SHEET 'Pipeline' DESCRIPTION 'Open opportunities by stage'
)
)
Example - a daily CSV export written to a mounted network share:
CREATE OR REPLACE JOB daily_inventory_export
REFRESH 'daily'
AS SEND REPORT inventory_export
USING `file`
OPTIONS (
path = '/mnt/finance-share/reports/'
)
ATTACH (
FORMAT 'CSV' FILENAME 'inventory_{{yyyy-MM-dd}}.csv'
QUERY inv AS (SELECT * FROM timbr.inventory_item)
)
Example - an on-demand job (REFRESH 'none') that is triggered manually:
CREATE OR REPLACE JOB send_people_report
REFRESH 'none'
AS SEND REPORT people_report
USING `email_ops`
OPTIONS (
recipients = '[email protected]',
subject = 'People Report',
body = 'Please find the people report attached.'
)
ATTACH (
FORMAT 'CSV' FILENAME 'people.csv' QUERY people AS (SELECT * FROM timbr.person)
);
RUN JOB send_people_report;
Options reference
SEND REPORT options
| Option | Applies to | Description |
|---|---|---|
recipients | Email (required) | Comma-separated recipient addresses - one user or many |
subject | Email (required) | Email subject. Supports {{date}} patterns |
body | Email body - plain text, or HTML when body_type = 'html'. Supports {{date}} patterns | |
body_type | text (default) or html | |
path | File, S3, Azure (required) | Output directory or folder URI. Supports {{date}} patterns and {{variable.name}} |
overwrite | S3, Azure | false (default): the send fails if the file already exists |
sse / sse_kms_key_id | S3 | Server-side encryption (AES256 or aws:kms) and the KMS key ID |
righttoleft | All | true / false (default false). RTL layout for Excel sheets and the plain-text email body |
excel_table_format | Excel | Excel table style name, e.g. TableStyleMedium9 |
excel_header_background_color | Excel | Header fill when no table style is used: NONE (default), BLUE, GREEN, ORANGE, TEAL, GREY, RED |
table_header_color | Excel | Header text color: AUTO (default), BLACK, WHITE |
excel_filter_table | Excel | Column filter drop-downs: true (default) / false |
table_limit | Excel | Max rows per sheet. Default 50000, maximum 1048576 |
excel_autosize | Excel | Fit each column to its content: true (default) / false (see Column width and wrap) |
excel_max_width | Excel | Maximum width of an auto-fitted column, in characters (1-255) |
excel_column_width | Excel | The same fixed width for every column, in characters (1-255) |
excel_column_widths | Excel | Fixed widths for specific columns: 'column:width,...' |
excel_wrap_text | Excel | Wrap long text inside cells: true / false (default) |
skip_if_empty | All | true: don't deliver when every attached query returns no rows. A query name: don't deliver when that query returns no rows. The run is recorded as SKIPPED |
save_results | All | true: keep each query's result set for the run (see Saved results) |
validate | Stored reports | false: don't run the queries to check them at CREATE / ALTER |
default_format | Stored reports | Format of the attachment created by ALTER REPORT ... ADD QUERY without TO ATTACHMENT. CSV (default) or XLSX |
`variable.{name}` | All | The value of a variable for this run |
Excel options apply to Excel attachments on every channel. Options stored on a report can be overridden key by key in any SEND REPORT or PREVIEW REPORT.
ATTACH elements
| Element | Description |
|---|---|
FORMAT | 'CSV', 'XLSX' or 'EXCEL' |
FILENAME | Attachment / output file name. Supports {{date}} patterns and {{variable.name}} |
QUERY name AS (sql) | The query whose results populate the file / sheet |
ONTOLOGY name / DATASOURCE name | Optional, after the query name. Run this query in another ontology or on a specific datasource |
SHEET 'name' | Worksheet tab name (Excel). Requires the parenthesized form |
DESCRIPTION 'text' | Title row above the table (Excel). Supports {{date}} patterns |
CONDITIONAL_FORMAT '[...]' | JSON array of cell-coloring rules for this query (Excel only) |
( ... , ... ) | Comma-separated queries inside parentheses create a multi-sheet Excel workbook |