Lock the grid
functionalOne click writes the result exactly as it looks now into the query, so it comes back the same on every run.
Arrange a result the way you want it - drag columns, hide a few, set widths, sort, filter, color, pivot or chart - then click the lock. SQLly writes the result, exactly as it looks now, into the query as SQLly directives. The next run, or a teammate opening the same file, gets the same grid.
Where the lock is
A small lock icon sits in front of every result set's name:
- Tabbed layout - on the result's tab label.
- Stacked layout - on the card header.
- Canvas layout - on the cell header.
The icon is highlighted when the query already carries a lock block.


What it writes
One block comment at the top of the statements that ran, holding a -- sqlly line for each part of the result:
/* sqlly lock — SQLly wrote this from the result grid; click the lock on the result to refresh it.
-- sqlly view: pivot
-- sqlly layout: tabbed
-- sqlly grid: order=Region, Rep, Total, Created; hide=Notes; freeze=1; sort=Total desc, Rep; filter=Region is West
-- sqlly format: column=Total; number=2; width=40dp
-- sqlly format: column=Rep; width=60dp
-- sqlly conditional: column=Total; when=> 10000; fill=#E3F4E8; text=#1E7B34; bold
-- sqlly conditional: column=Total; bar=#5B9BD5
-- sqlly pivot: row:Region; column:Year; value:Total:sum
-- sqlly chart: kind:bar; label:Region; values:Total
*/
SELECT Region, Rep, Total, Created, Notes FROM sales;
The block captures:
| What you see | Written as |
|---|---|
| Column order, hidden and frozen columns, sort, grouping, column filters, and foreign-key labels | grid: |
| Per-column formats, rounding, and column widths | format: |
| Conditional formatting rules for the result's columns | conditional: |
| Computed columns and their formulas | column: |
| The pivot and the chart setup | pivot: and chart: |
| Which view is open: grid, pivot, or chart | view: |
| The results layout: stacked, tabbed, or canvas | layout: |
| Which result has focus, result names, and stacked row allotments | focus:, name, and lines: |
Widths are written in dp, a unit that follows the grid's font size, so a column keeps showing about the same characters on a teammate's screen with a bigger or smaller font.
Clicking again
- The block always matches the screen. Click the lock again after changing the grid and SQLly rewrites the block to match what is on screen now.
- Nothing outside can contradict it. Directives of the kinds the lock writes that sit elsewhere in the code that ran - a
grid:orformat:line you wrote by hand, say - are folded into the block. - One undo. Each click is a single edit, so ⌘Z (CtrlZ on Windows and Linux) puts the query back.
What it leaves out on purpose
- Mask reveals. Revealing a masked column for a moment is not recorded, so a lock never unmasks data for the next reader.
- Parameters and variables.
param:andsetlines stay where you wrote them. - Canvas placement.
result:cells and the canvas size (2x2) stay as you wrote them. - Filter Rows… conditions the column filters can't express. Use Add Active Filters to WHERE to keep those in the SQL instead.
- Settings › Results column overrides. Those already apply everywhere, so they are not copied into the query.
Editing the block by hand
The block is ordinary text. Inside a comment that opens with /* sqlly lock, each
-- sqlly line works exactly as if it were written on its own line, and the block's
first directive line counts as the query's first line for view:. The opener line
must start with /* sqlly lock, and the block ends at a line that is just
*/. Any other block comment still switches off the directives inside it, which is a
handy way to disable a few lines for a while.