SQLly notebooks, take two

The first SQLly notebook hid in the command palette. The rebuild: SQL-first cells, local files, read-only by default, and nothing runs on open.

By

SQLly has had a notebook since 0.67.0, at the end of August. If you never noticed, that's on me. The only way to open one was the command palette. There was no File menu item, and Run Cell didn't have a key. You had to already know it existed.

It wasn't a terrible first version. You could mix SQL and Markdown cells, read an earlier cell by name, share a few parameters in a bar at the top, and save the whole thing as a small text file without the results. But Run All went top to bottom and stopped at the first error, parameters were plain text, and nothing knew which cell depended on which. It was a script with headings.

So I rebuilt it. This is the first of ten posts about the new notebooks: what they do, how they work, and where they still fall short. This one covers why, and what's different.

Notebooks are now something you can actually find: File ▸ New Notebook.

Cells know what they read, start read-only, and save as plain .sqllynb files you can review in Git. Opening a notebook never runs anything.

A SQLly notebook with Markdown and SQL cells in the middle, the outline of headings on the left rail and the inspector for the selected cell on the right
A notebook: headings in the outline on the left, named SQL cells that read each other, and the inspector for the selected cell on the right.
Building a SQLly notebook from nothing: a heading, a base query named orders, a second cell that reads it with {{orders}}, then an edit that marks the reader out of date until Run All.

Real recording · typing sped up · Northwind demo data

Building this post's notebook from nothing, recorded in the app: a heading, a base query, a second cell that reads it by name, and an edit that makes it go stale. The typing is sped up; nothing else is. Watch the whole recording, with chapters.

What I wanted a SQL notebook to be

Most of the SQL notebooks people rave about are hosted web apps. You hand them your database credentials, their servers run the queries, and you look at the results in a browser tab. Some of them are very good. Jupyter runs on your own machine, but it's a Python tool first, and SQL is something you bolt on with magics.

SQLly is a desktop SQL client. I wanted a notebook that fits that: one that works on the connections you already have, keeps everything on your computer, and doesn't make you nervous about pointing it at production. Four rules came out of that.

Every cell is SQL on a real connection

A SQL cell is ordinary SQL against a connection you've saved in SQLly, with the same IntelliSense as a query tab. Give a cell a name and another cell can read it as if it were a table, by writing {{orders}}. When both are on the same connection, SQLly folds the first query into the second as a common table expression, so the database gets one query and nothing is copied out. Each cell can also have its own connection, with its environment badge on it, so dev and prod can sit side by side.

Everything stays on your computer

A notebook is one JSON file. Results don't go in it (there's one file setting that keeps capped snapshots, and it's off by default), so a re-run doesn't change the file and a commit doesn't leak yesterday's numbers. Run history, saved results and a small DuckDB database per notebook live in SQLly's data folder on your machine. There's no SQLly cloud in the middle, and even schedules run on your own computer's scheduler. The exceptions are ones you set up: an AI cell pointed at a cloud model, which shows you what it will send and asks first, and webhook alerts.

Read-only unless you say otherwise

A new SQL cell runs on a copy of its connection with SQLly's read-only setting on, and where the engine supports it, inside the database's own read-only session. A cell that needs to write has to be switched over one cell at a time with Allow writes, and its statements still go through the usual change review.

Opening a notebook runs nothing

A notebook from a colleague, a Jupyter file, or a git pull that changed its SQL opens behind a banner. You can read every cell, but nothing runs until you trust it and choose which of its connections it may use. I'll cover how that works, and a bug in my own first version of it, in the last post of the series.

A notebook opened from another computer, with a banner across the top saying nothing runs until it is trusted and a Trust notebook button
A notebook made on another computer: every cell is readable, nothing runs until you press Trust notebook.

What's in a notebook now

SQL and Markdown are still the core. The other cell kinds read another cell's result and do something with it, usually without sending a query of their own. There are parameter cells with typed inputs, charts, tables, pivots, KPI tiles, formulas, transforms, column profiles, tests, diffs, query plans, entity detail, file attachments, AI cells and dashboards. The ones that read another cell's rows say when they're only looking at part of a result. A chart that quietly covers the first 100,000 rows of a bigger result is worse than no chart.

Every cell has a state badge. Not run, Up to date, Out of date, Failed, Blocked and a few more. Change a query and everything downstream of it is marked out of date, and stays marked until you run it or undo the edit. Runs are recorded, so you can open a past run's results or compare two runs and see whether the SQL, a parameter, the connection or the data moved.

The row of add-cell buttons under the last cell of a notebook, one button for each kind of cell, starting with SQL cell and Markdown cell
The add-cell row under the last cell has a button for every kind of cell.

You can find it this time

File ▸ New Notebook and File ▸ Open Notebook are where you'd look for them. If you're already halfway through a script, right-click its tab and choose Open as Notebook, or Open as Notebook, One Cell per Statement, which splits it the same way Run does, on ; and GO. The new notebook keeps the tab's connection.

The keys are the ones you probably expect if you've used Jupyter. ⌘Return runs a cell, ⇧Return runs it and moves on, ⌘⇧Return runs everything. Esc switches to command mode, where J and K move between cells, A and B insert, D D deletes, and M and Y turn a cell into Markdown or SQL. The editing basics the first version lacked are in too: select several cells and act on them together, copy and paste cells between notebooks, drag to reorder, undo and redo for changes to the cells themselves, and find and replace across the whole notebook.

Old notebooks still open. A .sqlnb.json file from the first version keeps its cell_N ids as cell names, so {{cell_2}} still works, and its cells that change data keep working with writes already allowed. Saving writes a new .sqllynb file and leaves the old one alone. Jupyter .ipynb files from JupyterLab, VS Code and Azure Data Studio open too, with code cells as SQL and outputs dropped, which matters if you're one of the people moving off Azure Data Studio.

SQLly's File menu pulled down, with New Notebook, Open Notebook and Save Notebook listed among the other file commands
The File menu, where the first version should have been all along.

What it doesn't do

There's no Python. Code cells from a Jupyter notebook open as SQL cells whatever language they were written in, so a Python cell won't run. Turn it into Markdown or delete it. There's no real-time multiplayer and no hosted publishing. Collaboration means a file in Git, with a CLI that turns notebooks into readable diffs.

Schedules only run while your computer is on and, unless you turn on lingering on Linux, while you're logged in. The app has no schedule editor yet, and there are no email alerts. The command-line runner only runs SQL, Tests, KPI and data attachment cells so far. In the browser build, the local DuckDB database, transforms, attachments and AI cells aren't available.

Each post in this series has a limits section like this one, and most docs pages under Notebooks end with one. I'd rather list the gaps myself than have you find them halfway through an investigation.

The rest of the series

Try it

The getting started page builds a small notebook in about five minutes on any database SQLly connects to. If you used the old palette-only notebook, your files open in the new one. If something's broken or confusing, tell me. Good or bad, I want to hear how it goes.