Switchboard Docs
Reference

SQL reference

Table references, dialects, and query boundaries

Use SQL to query models and source resources, or to define a model's data. A resource is one table or dataset from a connected source.

Table references

Use the IDs returned by the data browser or MCP discovery tools. Display names and IDs can differ.

ReferenceMeaning
{{models.model_id}}A built model's data
{{sources.source_id.resource_id}}A resource from a connected source

Replace each placeholder with the intended ID. Keep the double braces. Use Data browser, get_models, or get_source_details to find the available data.

SQL dialect

The lakehouse uses Trino SQL. Some existing query paths can show PostgreSQL. Use the dialect shown in the editor or returned by the MCP tool for that query. Do not choose it from the table's source system.

For Trino, use CAST(value AS type) instead of PostgreSQL's value::type cast. Use LOWER(column) LIKE 'pattern' with a lowercase pattern for a comparison without case. Do not use ILIKE. SQL errors identify expressions that need correction.

Example

These model and column names are invented. Replace them with names from your workspace.

SELECT
  order_date,
  SUM(net_revenue) AS net_revenue
FROM {{models.orders_output}}
WHERE order_date >= DATE '2026-01-01'
GROUP BY order_date
ORDER BY order_date

Check the model's definition before choosing a revenue field. A query that runs can still use the wrong business definition.

Read queries and model changes

The SQL editor and MCP query tools read data. They do not replace the model editor, where saved SQL defines a model build. A SQL explore saves a query as a document tile's data source.

The accepted read statements depend on the workspace's query mode. Use the editor or tool description for that mode. The query connection refuses writes.

For MCP queries, use the tool's limit and offset arguments for paging. Read has_more to determine whether additional pages remain. See MCP tools for defaults and limits.

Formulas in the context layer

Property and aggregation formulas use their own field references:

ReferenceMeaning
{{prop.model_id.property_id}}A property, or reusable field definition
{{agg.model_id.aggregation_id}}An aggregation, or reusable summary calculation

These references belong in the corresponding model formulas. They are different from the table references used after SQL FROM. See define an aggregation for formula setup.

On this page