Named cells and references
funcionalName a cell and read its result from another with {{name}}: how references are folded into SQL, renamed, and reported when they go in a circle.
Give a cell a name and other cells can use its result as if it were a table: write the name in double curly braces. That is how a notebook grows from one base query into a set of small, readable steps instead of one long script, and it is how SQLly knows which cells depend on which.
-- cell "orders"
SELECT o.OrderID, o.CustomerID, o.ShipCountry, o.Freight
FROM dbo.Orders AS o
WHERE YEAR(o.OrderDate) >= 1997
-- another cell
SELECT ShipCountry, SUM(Freight) AS Freight
FROM {{orders}}
GROUP BY ShipCountry
Naming a cell
Select the cell and type a name in the inspector's Nombre field. A name must start with a letter or underscore and use only letters, digits and underscores, and it must be unique in the notebook. SQL reserved words (in any of the dialects SQLly checks) and the word param are refused: "This word is reserved in SQL; choose another name". Names are not case-sensitive, so {{Orders}} y {{orders}} are the same cell.
Every cell also has an id (shown in the inspector, such as c_qm4tz7a2kd). {{c_qm4tz7a2kd}} works too, and an id reference never changes when the cell is renamed. Ids are matched exactly, including case. Named cells are listed on the left rail's Variables page and in the Outline.
How a reference becomes SQL
When both cells run on the same connection and the referenced cell is a single read-only query, SQLly folds it into the cell that reads it as a common table expression and sends one query. Nothing is copied out of the database, and the database can optimize the whole thing. The details differ by engine:
| Motor | What SQLly writes |
|---|---|
| PostgreSQL, MySQL and MariaDB, SQLite family, Oracle | The referenced query becomes a CTE, kept whole, even when it has its own WITH (these engines allow a nested WITH). |
| SQL Server | SQL Server doesn't allow a WITH inside a CTE, so the referenced query's own CTEs are lifted into the outer WITH list. If two would end up with the same name, or one would hide a table name the query uses, SQLly refuses with a message instead of guessing; rename one. A trailing ORDER BY sin TOP o OFFSET is dropped (it means nothing inside a CTE), and a referenced query ending in FOR XML, FOR JSON o FOR BROWSE can't be folded. |
A cell's own leading WITH (y WITH RECURSIVE) is merged with the folded ones. References inside strings, comments, quoted identifiers and dollar-quoted bodies are ignored, so '{{orders}}' in a string stays text. Parameters are filled in after the references are folded. Run Export ▸ Convert to SQL Script to see the folded SQL for the whole notebook.
A reference can't be folded, and the cell reports why, when the referenced cell:
- runs on a different connection, or on the notebook's local data: run the reading cell on Local data instead, which copies the result in first (see Join across connections);
- is not a query: more than one statement, a statement that changes data, or something other than a SELECT;
- is not a SQL cell (a transform, an attachment): read it from a local data cell.
orders that itself reads FROM orders turns into a CTE that refers to itself when another cell folds it in, and engines refuse that. Call it recent_orders.References in other cells
- Markdown cells can show a formula cell's value or a parameter:
Average order: {{aov}},Region: {{param.region}}. References inside code spans and fenced code blocks stay as written. - Chart, table, pivot, KPI, profile, test and diff cells read their input through their Input picker rather than
{{…}}; the link still shows in lineage and still makes them out of date when the input changes. - Fórmula cells name other cells directly (
sum(orders.Freight)); see Formulas and transforms. - Parámetros are written
{{param.name}}in Markdown and in SQL, and SQL can also use the:namey@nameplaceholders. See Parameters and inputs.
Renaming
Rename a cell in the inspector and every {{old_name}} in other SQL and Markdown cells is rewritten to the new name, and so is every formula that names it (sum(orders.Freight) se convierte en sum(recent_orders.Freight)). References written with the cell's id are left alone (they still point at the same cell). Clearing a cell's name rewrites its references to the id, so nothing breaks. A rename is one undo step, and undoing it puts the old name back in the cells that refer to it too.
The same rewriting happens when you rename a cell through find and replace, and when you paste copied cells: references inside the pasted cells point at the pasted copies, and a pasted name that would clash gets a suffix (orders_2).
Seeing the dependencies
The left rail's Lineage page lists, for every SQL cell, what it reads and what uses it ("Reads: orders · Used by: none"), and the inspector shows Reads from y Used by for the selected cell, each a link. Visual cells add column-level lineage in their Lineage panel; see where a chart's data came from.


Circular references
If cell A reads B and B reads A, no order can run them. SQLly reports the whole loop and suggests which reference to remove, preferring a reference that reads from further down the notebook:
These cells depend on each other in a loop: by_country → orders → by_country
Remove the reference to by_country from orders
Cells on or behind the loop are blocked until it is broken; everything else still runs. Check Without Running y sqlly-cli notebook validate report loops and references to cells that don't exist without running anything.