Skip to content

Queries & exports

The Query page is Tessule’s ad-hoc analysis surface: a SQL console over your workspace’s data. Every data table in the workspace is queryable as an ordinary SQL relation, so anything a SELECT can express — joins across tables, aggregation, grouping, subqueries — works directly. Results appear in a grid, can be exported to CSV or Excel, and a query worth keeping can be saved, parameterised with variables, and reused as the data source behind charts and dashboards.

If you only remember one thing: query access is all-or-nothing, never filtered. The SQL engine cannot apply per-row or per-field permission filters, so instead of silently narrowing your results it refuses to run at all for anyone whose record visibility is restricted anywhere in the workspace. If a query runs, you are seeing everything; if your visibility is restricted, you get a clear “unavailable” answer rather than a misleading partial result.


  • Run queries — requires the query:execute action, which every built-in role (Admin, Member, Reader) grants, plus unrestricted record visibility (see Permissions and query results below — this second condition is what actually decides who can run SQL).
  • See the Query page — the page lives in the builder area of the app (Admin → Query), which sits behind the builder:access action: admin-only by default, grantable to power users through a custom role.
  • View saved queries — savedQueries:read, granted to all built-in roles.
  • Create, edit, delete saved queries — savedQueries:manage, granted to Members and Admins.
  • Start and download CSV exports — same gate as running the query: query:execute plus unrestricted visibility.

There is no per-query ownership or sharing model: every saved query belongs to the workspace. Anyone with savedQueries:manage can edit or delete any saved query, whoever created it (the creator is recorded on the query, but it grants no special rights).


A query is a single SQL SELECT statement, executed read-only against your workspace’s own database schema. Each data table is exposed under its API name (the lowercase name shown in the schema editor), with one column per field plus the built-in id, createdAt, and updatedAt columns:

SELECT region, COUNT(*) AS deals, SUM(amount) AS pipeline
FROM deals
WHERE stage != 'closed_lost'
GROUP BY region
ORDER BY pipeline DESC

Because this is real SQL, joins, subqueries, HAVING, window functions, and date arithmetic all behave as they do in PostgreSQL. Three system views are also available to join against:

View Columns Contents
sys_users id, name, email, status The people this workspace’s records can name: current members (active) and former ones (inactive), so an owner who has left still resolves to a name
sys_usergroups id, name, description Active groups in this workspace
sys_group_members group_id, user_id Who is in which active group: one row per membership, joining sys_usergroups.id to sys_users.id. A person who has left the workspace keeps their memberships; filter on sys_users.status to see current members only

Useful for turning an owner id into a person’s name in a report, or for listing each group’s members:

SELECT g.name AS group_name, u.name AS member, u.email
FROM sys_group_members m
JOIN sys_usergroups g ON g.id = m.group_id
JOIN sys_users u ON u.id = m.user_id
WHERE u.status = 'active'
ORDER BY g.name, u.name

The same three tables are listed, read-only, under System Tables on the Tables page, where you can open each one to browse its rows.

Not every field is a column. A formula field is stored (the database recomputes it on every write), so SQL reads it like any other column. A lookup, a rollup, or a computed column is evaluated when records are read through the app and the record API — nothing is stored — so the SQL table has no such column, and SELECT avg_rating FROM artworks is refused with COLUMN_NOT_FOUND.

That is a decision, not a gap: giving SQL its own copy of the number would mean two ways of computing one value that could drift on soft-deleted rows or rounding. Instead, the refusal tells you what the column is and hands you the expression the app evaluates, written against the table aliased as t:

SELECT title,
(SELECT AVG(c."score") FROM "artwork_ratings" c
WHERE c."artwork" = "t".id AND c.deleted_at IS NULL) AS avg_rating
FROM artworks t

The AI query assistant receives the same hint when its draft selects one, and the MCP get_table_schema tool lists each such column with queryable: false and its sqlEquivalent. Dashboards and saved queries therefore restate aggregates rather than selecting rollup columns — see Derived data for what each kind is.

The engine validates before executing, and fails closed:

  • Exactly one SELECT statement. Writes (INSERT/UPDATE/DELETE), DDL, and multi-statement input are rejected — and the connection itself is read-only at the database level, so nothing can slip through.
  • No schema-qualified names. References like public.users are rejected; the connection is confined to your workspace’s own schema by the database, so other tenants’ data and platform tables are unreachable by construction.
  • Time budget. An interactive query is aborted after ~15 seconds. Narrow the query, or use a background export — exports get a far larger budget because they run off the request path.
  • With no LIMIT, a default LIMIT 100 is applied.
  • The hard ceiling is 10,000 rows per interactive query, enforced outside your SQL — a larger LIMIT is capped, and the response’s hasMore flag tells you the result was cut short. To get more rows, use a background export (up to 100,000 rows by default).
Permission gate query:execute + unrestricted visibility Validation one SELECT only, variables filled in Read-only engine workspace schema only, writes impossible Results grid up to 10,000 rows CSV export job up to 100,000 rows
Every query — interactive or export — passes the same gate and the same validation before touching data.

This is the section to read before granting query access widely.

Raw SQL cannot be row-filtered: once a statement is running, the engine has no way to hide “rows owned by someone else” or “the salary column” from it. So Tessule enforces the rule before execution, per statement, via POST /query’s permission gate:

  • The caller must hold query:execute (all built-in roles do), and
  • the statement must not read a table on which the caller’s record visibility is restricted: a private table where their read scope is narrower than workspace, a table a row rule governs for reading, or a table with a private field they cannot read.

“Read” means every table the statement names anywhere: a FROM, a JOIN, a subquery, a CTE, a UNION branch. A SQL view counts as the tables its definition reads, so a view over a restricted table is refused with it.

In practice:

  • Admins can always run queries — they bypass row and field filters everywhere, so they are restricted nowhere.
  • Members and Readers can run any statement over the tables open to them. A statement that reads a table restricted for them is refused with a 403 that names the table; every other statement runs. Making one table private, or one field on it private, closes queries over that table for a non-admin — not queries over the rest of the workspace.
  • A few internal tables close with them. When a caller is restricted anywhere, the stage-history table, the activity-links table and a multi-reference field’s junction table are refused to them too, because they list records by id across every table. The table and field metadata tables stay readable.

Restricted users are not locked out of data — they still read records through the normal record pages, lists, and views, where row and field filters apply properly. They lose the raw-SQL shortcut only for the tables that are restricted for them.


A query can be a template: {{name}} placeholders in the SQL are filled in at run time from value controls shown above the results. Values are substituted as escaped literals server-side before validation, so a variable can never smuggle in extra SQL.

SELECT * FROM deals
WHERE amount >= {{min_amount}}
[[AND region = {{region}}]]
  • [[ ... ]] marks an optional block: when every variable inside it is unset (a select left on “All”), the whole block is dropped from the SQL — the idiomatic way to build removable filters.
  • Declare each variable’s behaviour under Variables → Configure on the Query page. Types:
Type Behaviour
text / number Free-form scalar, substituted as an escaped literal
select Single choice from a dropdown
multiselect Multiple choices, substituted as a parenthesised list for IN {{name}}
daterange A from/to pair referenced as {{name.from}} / {{name.to}} (from inclusive, to exclusive); relative presets resolve at run time
  • Select options can be a static list or an options query — SQL whose first column supplies the values (second column, if present, the labels).
  • Include "All" on a select adds an All choice that leaves the variable unset, activating the [[ ... ]] drop behaviour.
  • Each variable can carry a default value; charts and dashboards built on the query inherit its variable definitions.

Save stores the SQL and its variable definitions under a name; Load brings any saved query back into the editor. Saved queries are workspace-shared — everyone with savedQueries:read sees the same list — and they are the building block the rest of the analytics surface stands on: a chart can point at a saved query, and a dashboard tile can render one directly as a table.

Two behaviours worth knowing:

  • Editing a saved query changes every chart and dashboard built on it, immediately. The query list shows usage chips (which charts and dashboards reference each query) so you can see the blast radius; when in doubt, use Duplicate and edit the copy.
  • References are soft. Deleting a saved query does not break or delete the charts and dashboards that used it — their tiles show “This saved query no longer exists” until re-pointed.

The REST shape mirrors the UI: GET /queries, POST /queries, PUT /queries/{queryId}, DELETE /queries/{queryId} — see API access.

Save as view promotes the SELECT in the editor into a SQL view — a read-only, table-like object that appears in the tables list and can be read like any table (including over the API). Creating one requires tables:manage; reading one back requires the same unrestricted visibility as running SQL, because a view can select from any workspace table. See Views for the full story.


The Query page (and the chart editor) includes an AI query assistant: describe what you want to know in plain language, and it drafts the SQL — validated against your workspace’s real tables — for you to review, run, and save. The assistant only drafts; nothing runs until you run it. It appears when AI features are enabled for your organization. See AI assistants.


There are three export buttons over the results grid, and they do different things:

  • Export shown — downloads the rows currently loaded in the grid as a CSV, built in your browser. Instant, and exactly what you can see — capped at the interactive 10,000-row limit.
  • Export as Excel — the same rows as one .xlsx worksheet, also built in your browser: numbers are number cells, the header row takes the workspace’s brand colour and the sheet its font (see Branding).
  • Export full result — starts a background export job via POST /query/exports. The server re-runs the query on a worker with a much larger row ceiling and time budget, writes a complete artifact, and the page polls the job until the download starts automatically. The request’s format chooses csv (the default) or xlsx.
  • Same rules as running the query. The export goes through the identical validation and the identical permission gate — exporting cannot be used to see anything a live query couldn’t, and it draws on the same daily query quota.
  • Row ceiling: 100,000 rows by default (an entitlement your plan may raise). An Excel export is built in memory, so its ceiling is the smaller of that entitlement and 200,000 rows. When the ceiling cuts a result short the job reports truncated: true and the UI says so — truncation is visible, never silent.
  • CSV format: one file, UTF-8 with a BOM (so spreadsheet apps detect the encoding), a header row of column names, standard RFC 4180 quoting, and JSON-serialised object/array cells. Cells that could be interpreted as spreadsheet formulas (starting =, +, -, @, or a tab) are prefixed with a quote to neutralise formula injection.
  • Excel format: one .xlsx workbook with one worksheet, a frozen header row, and cells typed from the column (numbers as numbers, booleans as booleans, dates as the day they name, JSON for object and array cells). Nothing is written as a formula, and formula-looking text carries the same quote prefix as the CSV. The header row is filled with the workspace’s primary brand colour and the sheet uses its brand font when either is set.
  • Time budget: ~10 minutes of execution. A query that exceeds it fails with advice to narrow the query.
  • Concurrency: at most 2 exports per workspace can be queued or running at once; a third attempt returns 429 — retry when one finishes.
  • Where the file goes: the job (GET /query/exports/{jobId}) returns a short-lived download link — valid for about 5 minutes; re-fetch the job for a fresh one. The artifact itself is downloadable for 24 hours after the job succeeds, then it is deleted.
  • Requester-only: an export was built under the submitting user’s access, so only that user can see the job or obtain its download link. Anyone else gets a 404, as if the job didn’t exist. To share the data, share the file — or better, share the saved query.

A saved query can run on a schedule and email its result to people in your workspace. Load the saved query and choose Schedule delivery.

Each schedule holds three things: the saved query, a cadence, and a list of recipients. Everything else follows the ordinary export path, so a delivered report is exactly the CSV you would get from Export full result.

Recipients are workspace members you pick from a list, never typed-in email addresses. That is a rule about the data, not a UI shortcut: a query runs without row-level filters, so a report contains everything the query selects. Everyone on a report therefore has to be someone who could have run it themselves — an active member whose record visibility is unrestricted.

The rule is checked twice. A recipient who does not qualify is refused when you save the schedule, with a message naming what is wrong. A recipient who later leaves the workspace, or has their visibility narrowed, is dropped silently at the next delivery and the schedule records how many were skipped.

  • Cadence: standard 5-field cron, in UTC, and no more often than once an hour. The dialog offers presets for the common cases and accepts a custom expression for the rest.
  • Runs as you: the query executes under the authority of whoever created the schedule, re-checked at every firing. If that person loses the right to run queries, the report stops and says so rather than continuing under borrowed access.
  • Empty results: by default a run that returns no rows still emails the recipients an empty report. Tick Don’t send when the query returns no rows for a list that should only arrive when there is something on it, such as the follow-ups that are due; the schedule still records that it ran.
  • The email carries a link, not a file. Following it downloads the report through the app, which is where the recipient check happens. The artifact lives for 24 hours; after that the link explains that the report has expired and the next delivery will bring a fresh one.
  • Send now starts an extra delivery immediately and leaves the cadence untouched — tomorrow’s scheduled send still happens.
  • Missed windows collapse. If deliveries could not run for a while, you get one report when they resume, not one for every window that passed.
  • Failures are visible on the schedule: a deleted saved query, a recipient list nobody on it can receive, or an export that failed all leave a plain explanation on the row.
  • Limits: at most 20 recipients per schedule and 50 schedules per workspace.

Ad-hoc SQL is the most expensive read a workspace can issue, so executions are metered:

Limit Default Notes
Query executions per day 20,000 per workspace Interactive runs and exports share this quota; an entitlement your plan may raise
Interactive rows per query 10,000 Hard cap; hasMore flags truncation
Interactive time budget ~15 seconds Statement aborted beyond it
Export rows per job 100,000 Entitlement; truncated flags the cut
Concurrent exports 2 per workspace 429 beyond it
Export artifact lifetime 24 hours Download link itself refreshes every ~5 minutes

Q: I get “Your record visibility is restricted on one or more tables; raw SQL queries are unavailable.”

Some table in the workspace is set to Private visibility and your role’s read scope on it is narrower than workspace, or a private field exists that your roles can’t read. Raw SQL is all-or-nothing (see Permissions and query results), so it’s refused. Either an admin widens your visibility, or you use the record pages and views, where filters apply per row.

Q: My query says it ran but I only got 100 rows.

With no LIMIT clause, the default page size of 100 is applied. Add your own LIMIT (up to 10,000), or use Export full result for more.

Q: COLUMN_NOT_FOUND for a field I can see on the record page.

If the message says the field is a lookup, rollup or computed column, it is computed when records are read and is not a column of the SQL table. The refusal includes the equivalent expression; paste it into your SELECT with the table aliased as t. See Computed values.

Q: “Table ‘X’ not found” — but I can see the table in the app.

Query by the table’s API name (lowercase, as shown in the schema editor), not its display name. The editor suggests table names after FROM and column names after WHERE, ORDER BY and a table alias’s dot as you type (Ctrl+Space asks for suggestions at any point).

Q: I edited a saved query and a dashboard changed for everyone. Can I roll back?

There is no version history on saved queries. The safe workflow is Duplicate, edit the copy, and re-point tiles when you’re happy. The usage chips on the saved-query list show which charts and dashboards a query feeds before you edit it.

Q: Can Readers run queries?

Yes — query:execute is in the Reader baseline — but only while their visibility is unrestricted, and they can only reach the Query page itself if granted builder:access (dashboards still work for them regardless, since tiles run queries without the page).

Open the app