Skip to content

The SQL tab

Every result owns a SQL query, and the SQL tab of the preview editor shows it. You can read it to see exactly what was computed, or edit it and run it again. The query runs on DuckDB, the database engine inside Totsum, on your machine.

The tab shows the query with syntax highlighting. The rows the query produces are shown below it, with their count.

There is no separate list of transformations in Totsum. Each filter, join, total by group or pivot is a query, and each query belongs to a result. To make one, ask the AI Assistant (“Filter sales to USA only”, “Join customers with orders”) and it writes the query into a new result, or edit the query of an existing result on this tab.

The chevron on the left divider opens the Available Tables catalog. It lists every table you loaded, with its columns and their types, and you can hover over an item to see its description, when it has one. Drag a table or a column name into the editor and it appears as a correctly quoted identifier. The editor also completes table and column names as you type.

  • Format rewrites the query with consistent indentation. Ctrl+Z (Cmd+Z on macOS) undoes it.
  • Add Comments asks the AI to annotate the query with what each part is for.

Both are available as soon as the editor holds a query. As soon as the text differs from the query currently applied, the tab shows ”● Unapplied changes” and two more buttons appear under the editor: Revert Changes, which discards your edits and restores the last applied query, and Apply SQL, which runs the query again and updates the chart, the data and the query flow. Before it runs, the query is validated: only a read-only SELECT query is accepted, and a query that does not parse shows its error under the editor instead of running.

  • Quote table and column names with double quotes: SELECT "Name" FROM "customers".
  • Common table expressions (WITH …), window functions, joins and subqueries are supported.
  • The dialect is DuckDB’s, which is close to PostgreSQL’s. A function from MySQL or SQL Server may not exist under the same name.

Applying a query rebuilds the result: the chart, the Data tab, the Statistics tab and the Query Flow. The Query Flow is retold from the new query, and it is shown only when Totsum can check that the retelling matches. A query too complex for that check shows the notice described on the Results page instead.

If the result is already in a follow-up report, the report keeps the rows and the query it froze when it was created.